1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2016-01-03 21:27:38 -05:00
parent 9509363f46
commit 096045614c
647 changed files with 11693 additions and 7648 deletions

View File

@@ -29,11 +29,8 @@ public class Xoh_consts {
, __inline_quote = Bry_.new_a7("\"/>")
, Space_2 = Bry_.new_a7(" ")
, A_bgn = Bry_.new_a7("<a href=\""), A_bgn_lnki_0 = Bry_.new_a7("\" title=\""), A_mid_xowa_title = Bry_.new_a7("\" xowa_title=\"")
, A_mid_id = Bry_.new_a7("\" id=\"xolnki_")
, A_end = Bry_.new_a7("</a>")
, Div_bgn_open = Bry_.new_a7("<div ")
, Div_end = Bry_.new_a7("</div>")
, Img_bgn = Bry_.new_a7("<img src=\"")
, Span_bgn_open = Bry_.new_a7("<span")
@@ -47,7 +44,6 @@ public class Xoh_consts {
, Code_bgn_closed = Bry_.new_a7("<code>")
, Code_bgn_open = Bry_.new_a7("<code")
, Code_end = Bry_.new_a7("</code>")
, Title_atr = Bry_.new_a7("\" title=\"")
, Id_atr = Bry_.new_a7(" id=\"")
, Style_atr = Bry_.new_a7(" style=\"")
, Atr_xowa_title_bry = Bry_.new_a7(Atr_xowa_title_str)

View File

@@ -39,5 +39,6 @@ public class Xoh_img_mgr {
itm.To_bfr(bfr);
}
}
public static final byte[] Bry__html_uid = Bry_.new_a7("xoimg_");
public static final String Str__html_uid = "xoimg_";
public static final byte[] Bry__html_uid = Bry_.new_a7(Str__html_uid);
}

View File

@@ -46,13 +46,13 @@ public class Xoh_page_wtr_wkr {
Bry_bfr page_bfr = Xoa_app_.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page bfr to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
if (page_mode == Xopg_page_.Tid_html && wiki.App().Api_root().Html().Page().View_html_generates_hdump()) {
Write_body(page_bfr, Xoh_wtr_ctx.Hdump, page);
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Html_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
}
else {
Write_body(page_bfr, Xoh_wtr_ctx.Basic, page);
Write_page_by_tid(view_mode, bfr, fmtr, page_bfr.To_bry_and_rls());
if (page_mode == Xopg_page_.Tid_html) // if html, write page again, but wrap it in html skin this time
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Html_utl.Escape_html_as_bry(bfr.To_bry_and_clear()));
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(bfr.To_bry_and_clear()));
wdata_lang_wtr.Page_(null);
}
}

View File

@@ -23,7 +23,7 @@ public class Xoh_page_wtr_wkr_ {
public static byte[] Bld_page_content_sub(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Bry_bfr tmp_bfr) {
byte[] subpages = app.Html_mgr().Page_mgr().Subpages_bldr().Bld(wiki.Ns_mgr(), page.Ttl());
byte[] page_content_sub = page.Html_data().Content_sub(); // contentSub exists; SEE: {{#isin}}
byte[] redirect_msg = Xop_redirect_mgr.Bld_redirect_msg(app, wiki, page);
byte[] redirect_msg = Xop_redirect_mgr.Bld_redirect_msg(app, wiki, page.Redirected_ttls());
return Bry_.Add(subpages, page_content_sub, redirect_msg);
}
public static byte[] Bld_page_name(Bry_bfr tmp_bfr, Xoa_ttl ttl, byte[] display_ttl) {
@@ -38,7 +38,7 @@ public class Xoh_page_wtr_wkr_ {
public static void Bld_head_end(Bry_bfr html_bfr, Xoae_page page) {
byte[] head_end = page.Html_data().Custom_head_end();
if (head_end == null) return;
int insert_pos = Bry_find_.Find_fwd(html_bfr.Bfr(), Html_tag_.Head_rhs);
int insert_pos = Bry_find_.Find_fwd(html_bfr.Bfr(), Gfh_tag_.Head_rhs);
if (insert_pos == Bry_find_.Not_found) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </head>");
return;
@@ -48,7 +48,7 @@ public class Xoh_page_wtr_wkr_ {
public static void Bld_html_end(Bry_bfr html_bfr, Xoae_page page) {
byte[] html_end = page.Html_data().Custom_html_end();
if (html_end == null) return;
int insert_pos = Bry_find_.Find_bwd(html_bfr.Bfr(), Html_tag_.Html_rhs, html_bfr.Len());
int insert_pos = Bry_find_.Find_bwd(html_bfr.Bfr(), Gfh_tag_.Html_rhs, html_bfr.Len());
if (insert_pos == Bry_find_.Not_found) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </html>");
return;

View File

@@ -43,9 +43,9 @@ public class Xohp_ctg_grp_mgr {
grp_fmtr.Bld_bfr_many(bfr, categories_lbl, itm_mgr);
}
}
class Xoh_ctg_itm_fmtr extends gplx.core.brys.Bfr_arg_base {
class Xoh_ctg_itm_fmtr implements gplx.core.brys.Bfr_arg {
public void Set(Xoae_page page, Bry_fmtr itm_fmtr) {this.page = page; this.itm_fmtr = itm_fmtr;} private Xoae_page page; Bry_fmtr itm_fmtr;
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
int ctgs_len = page.Category_list().length;
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
Bry_bfr tmp_href = Xoa_app_.Utl__bfr_mkr().Get_b128();

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
public class Dbui_cells_fmtr extends gplx.core.brys.Bfr_arg_base {
public class Dbui_cells_fmtr implements gplx.core.brys.Bfr_arg {
private final Dbui_cell_fmtr cell_fmtr = new Dbui_cell_fmtr();
private final Dbui_btn_fmtr btn_fmtr = new Dbui_btn_fmtr();
private Dbui_btn_itm[] btns;
@@ -30,7 +30,7 @@ public class Dbui_cells_fmtr extends gplx.core.brys.Bfr_arg_base {
this.row_key = row_key; this.row_itm = row_itm;
return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, cell_fmtr.Init(row_key, row_itm), btn_fmtr.Init(row_key, btns));
}
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
@@ -40,12 +40,12 @@ public class Dbui_cells_fmtr extends gplx.core.brys.Bfr_arg_base {
, " </div>"
), "vals", "btns");
}
class Dbui_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
class Dbui_cell_fmtr implements gplx.core.brys.Bfr_arg {
private byte[] row_key; private Dbui_row_itm row_itm;
private Dbui_val_fmtr val_fmtr;
public void Ctor(Dbui_val_fmtr val_fmtr) {this.val_fmtr = val_fmtr;}
public Dbui_cell_fmtr Init(byte[] row_key, Dbui_row_itm row_itm) {this.row_key = row_key; this.row_itm = row_itm; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
Dbui_col_itm[] cols = row_itm.Tbl().Cols();
Dbui_val_itm[] vals = row_itm.Vals(); int len = vals.length;
for (int i = 0; i < len; ++i) {
@@ -58,12 +58,12 @@ class Dbui_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
, " <div class='xo_cell'>~{html}</div>"
), "row_key", "val_idx", "html");
}
class Dbui_btn_fmtr extends gplx.core.brys.Bfr_arg_base {
class Dbui_btn_fmtr implements gplx.core.brys.Bfr_arg {
private byte[] row_key; private Dbui_btn_itm[] btns;
public Dbui_btn_fmtr Init(byte[] row_key, Dbui_btn_itm[] btns) {
this.row_key = row_key; this.btns = btns; return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
int len = btns.length;
Io_url img_dir = gplx.xowa.htmls.heads.Xoh_head_itm__dbui.Img_dir();
for (int i = 0; i < len; ++i) {

View File

@@ -33,10 +33,10 @@ public class Dbui_tbl_fmtr {
, "</div>"
), "tbl_key", "width", "origin", "delete_confirm_msg", "head_cells", "data_rows");
}
class Dbui_head_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
class Dbui_head_cell_fmtr implements gplx.core.brys.Bfr_arg {
private Dbui_tbl_itm tbl;
public Dbui_head_cell_fmtr Init(Dbui_tbl_itm tbl) {this.tbl = tbl; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
Dbui_col_itm[] cols = tbl.Cols(); int len = cols.length;
for (int i = 0; i < len; ++i) {
Dbui_col_itm col = cols[i];
@@ -49,13 +49,13 @@ class Dbui_head_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
, " <div class='xo_head xo_resizable_col' style='width:~{width}px;'>~{display}</div>"
), "width", "display");
}
class Dbui_row_fmtr extends gplx.core.brys.Bfr_arg_base {
class Dbui_row_fmtr implements gplx.core.brys.Bfr_arg {
private final Dbui_cells_fmtr cells_fmtr = new Dbui_cells_fmtr();
private final Dbui_val_fmtr val_fmtr = Dbui_val_fmtr_.new_view();
private final Bry_bfr row_key_bfr = Bry_bfr.new_(255);
private Dbui_tbl_itm tbl; private Dbui_row_itm[] rows;
public Dbui_row_fmtr Init(Dbui_tbl_itm tbl, Dbui_row_itm[] rows) {this.tbl = tbl; this.rows = rows; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
byte[] tbl_key = tbl.Key();
int len = rows.length;
cells_fmtr.Ctor(val_fmtr, tbl.View_btns());

View File

@@ -21,17 +21,17 @@ import gplx.xowa.htmls.bridges.dbuis.tbls.*;
public interface Dbui_val_fmtr {
Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val);
}
class Dbui_val_fmtr__view extends gplx.core.brys.Bfr_arg_base implements Dbui_val_fmtr {
class Dbui_val_fmtr__view implements gplx.core.brys.Bfr_arg, Dbui_val_fmtr {
private Dbui_val_itm val;
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.val = val; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add(val.Html());
}
}
class Dbui_val_fmtr__edit extends gplx.core.brys.Bfr_arg_base implements Dbui_val_fmtr {
class Dbui_val_fmtr__edit implements gplx.core.brys.Bfr_arg, Dbui_val_fmtr {
private Dbui_col_itm col; private byte[] row_id; private Dbui_val_itm val;
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.col = col; this.row_id = row_id; this.val = val; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
switch (col.Type()) {
case Dbui_col_itm.Type_id_str: input_fmtr_str.Bld_bfr_many(bfr, col.Key(), col.Width(), val.Data(), row_id); break;
case Dbui_col_itm.Type_id_text: textarea_fmtr_str.Bld_bfr_many(bfr, col.Key(), col.Width(), val.Data(), row_id); break;

View File

@@ -23,6 +23,7 @@ import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
public class Xow_hdump_mgr__load {
private final Xow_wiki wiki; private final Xoh_hzip_mgr hzip_mgr; private final Io_stream_zip_mgr zip_mgr;
private final Xoh_page tmp_hpg; private final Bry_bfr tmp_bfr; private final Xowd_page_itm tmp_dbpg = new Xowd_page_itm();
private Hash_adp_bry page_overrides;
public Xow_hdump_mgr__load(Xow_wiki wiki, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, Xoh_page tmp_hpg, Bry_bfr tmp_bfr) {
this.wiki = wiki; this.hzip_mgr = hzip_mgr; this.zip_mgr = zip_mgr; this.tmp_hpg = tmp_hpg; this.tmp_bfr = tmp_bfr;
this.make_mgr = new Xoh_make_mgr(wiki.App().Usr_dlg(), wiki.App().Fsys_mgr(), gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_lnx, wiki.Domain_bry());
@@ -36,12 +37,13 @@ public class Xow_hdump_mgr__load {
}
public boolean Load(Xoh_page hpg, Xoa_ttl ttl) {
synchronized (tmp_dbpg) {
if (page_overrides == null) page_overrides = Init_page_overrides(wiki);
if (!Load__dbpg(wiki, tmp_dbpg.Clear(), hpg, ttl)) return Load__fail(hpg); // nothing in "page" table
Xowd_db_file html_db = wiki.Data__core_mgr().Dbs__get_at(tmp_dbpg.Html_db_id());
hpg.Init(hpg.Wiki(), hpg.Url(), ttl, tmp_dbpg.Id());
if (!html_db.Tbl__html().Select_by_page(hpg)) return Load__fail(hpg); // nothing in "html_page" table
if (!html_db.Tbl__html().Select_by_page(hpg)) return Load__fail(hpg); // nothing in "html_page" table
byte[] src = Parse(hpg, hpg.Body_zip_tid(), hpg.Body_hzip_tid(), hpg.Body());
hpg.Body_(make_mgr.Parse(src, hpg, hpg.Wiki()));
hpg.Body_(src);
return true;
}
}
@@ -49,8 +51,15 @@ public class Xow_hdump_mgr__load {
private byte[] Parse(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] src) {
if (zip_tid > gplx.core.ios.Io_stream_.Tid_raw)
src = zip_mgr.Unzip((byte)zip_tid, src);
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1)
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1) {
byte[] page_override_src = (byte[])page_overrides.Get_by_bry(hpg.Ttl().Page_db());
if (page_override_src != null) src = page_override_src;
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
src = Decode_as_bry(tmp_bfr.Clear(), hpg, src, Bool_.N);
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
}
else
src = make_mgr.Parse(src, hpg, hpg.Wiki());
return src;
}
private void Fill_page(Xoae_page wpg, Xoh_page hpg) {
@@ -79,4 +88,19 @@ public class Xow_hdump_mgr__load {
if (redirect_id == -1) break;
}
}
private static Hash_adp_bry Init_page_overrides(Xow_wiki wiki) {
Hash_adp_bry rv = Hash_adp_bry.cs();
Io_url[] page_urls = Io_mgr.Instance.QueryDir_fils(wiki.Fsys_mgr().Root_dir().GenSubDir_nest("data", "page"));
int page_urls_len = page_urls.length;
for (int i = 0; i < page_urls_len; ++i) {
Io_url page_url = page_urls[i];
byte[] page_raw = Io_mgr.Instance.LoadFilBry(page_url);
int page_raw_len = page_raw.length;
int page_nl = Bry_find_.Find_fwd(page_raw, Byte_ascii.Nl, 0, page_raw_len); if (page_nl == Bry_find_.Not_found) continue;
byte[] page_ttl_bry = Bry_.Mid(page_raw, 0, page_nl);
byte[] page_src_bry = Bry_.Mid(page_raw, page_nl + 1, page_raw_len);
rv.Add_bry_obj(page_ttl_bry, page_src_bry);
}
return rv;
}
}

View File

@@ -35,7 +35,7 @@ public class Xow_hdump_mgr__load_tst {
// ( "[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
// ( "<div class=\"thumb tright\">"
// , " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" xowa_img='0' /></a>"
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
// , " test_caption"
// , " </div>"
@@ -49,7 +49,7 @@ public class Xow_hdump_mgr__load_tst {
// ( "[[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 class=\"xowa_media_div\"><xowa_play id='0'/><xowa_info id='0'/>"
// , " </div>"
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
// , " test_caption"
@@ -64,10 +64,10 @@ public class Xow_hdump_mgr__load_tst {
// ( "[[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 class=\"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=\"\" />"
// , " <img id=\"xoimg_0\" xowa_img='0' alt=\"\" />"
// , " </a>"
// , " </div><xowa_play id='0'/>"
// , " </div>"
@@ -93,7 +93,7 @@ public class Xow_hdump_mgr__load_tst {
// , " <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>"
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" xowa_img='0' /></a>"
// , " </div>"
// , " </div>"
// , " <div class=\"gallerytext\"><p>A1"

View File

@@ -50,7 +50,7 @@ public class Xob_link_dump_cmd {
tbl.Create_idx_2();
conn.Env_vacuum();
} catch (Exception e) {
Tfds.Write(Err_.Message_gplx_full(e));
Tfds.Dbg(Err_.Message_gplx_full(e));
}
}
}

View File

@@ -20,7 +20,7 @@ import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.btries.*
import gplx.langs.htmls.*; import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.vnts.*; import gplx.xowa.parsers.htmls.*;
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.parsers.hdrs.*;
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.xtns.cites.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.parsers.hdrs.*;
import gplx.xowa.htmls.core.*;
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*;
public class Xoh_html_wtr {
@@ -114,18 +114,18 @@ public class Xoh_html_wtr {
if (literal_apos > 0)
bfr.Add_byte_repeat(Byte_ascii.Apos, literal_apos);
switch (apos.Apos_cmd()) {
case Xop_apos_tkn_.Cmd_b_bgn: bfr.Add(Html_tag_.B_lhs); break;
case Xop_apos_tkn_.Cmd_b_end: bfr.Add(Html_tag_.B_rhs); break;
case Xop_apos_tkn_.Cmd_i_bgn: bfr.Add(Html_tag_.I_lhs); break;
case Xop_apos_tkn_.Cmd_i_end: bfr.Add(Html_tag_.I_rhs); break;
case Xop_apos_tkn_.Cmd_bi_bgn: bfr.Add(Html_tag_.B_lhs).Add(Html_tag_.I_lhs); break;
case Xop_apos_tkn_.Cmd_ib_end: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_rhs); break;
case Xop_apos_tkn_.Cmd_ib_bgn: bfr.Add(Html_tag_.I_lhs).Add(Html_tag_.B_lhs); break;
case Xop_apos_tkn_.Cmd_bi_end: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_rhs);; break;
case Xop_apos_tkn_.Cmd_bi_end__b_bgn: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_rhs).Add(Html_tag_.B_lhs); break;
case Xop_apos_tkn_.Cmd_ib_end__i_bgn: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_rhs).Add(Html_tag_.I_lhs); break;
case Xop_apos_tkn_.Cmd_b_end__i_bgn: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_lhs); break;
case Xop_apos_tkn_.Cmd_i_end__b_bgn: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_lhs); break;
case Xop_apos_tkn_.Cmd_b_bgn: bfr.Add(Gfh_tag_.B_lhs); break;
case Xop_apos_tkn_.Cmd_b_end: bfr.Add(Gfh_tag_.B_rhs); break;
case Xop_apos_tkn_.Cmd_i_bgn: bfr.Add(Gfh_tag_.I_lhs); break;
case Xop_apos_tkn_.Cmd_i_end: bfr.Add(Gfh_tag_.I_rhs); break;
case Xop_apos_tkn_.Cmd_bi_bgn: bfr.Add(Gfh_tag_.B_lhs).Add(Gfh_tag_.I_lhs); break;
case Xop_apos_tkn_.Cmd_ib_end: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_rhs); break;
case Xop_apos_tkn_.Cmd_ib_bgn: bfr.Add(Gfh_tag_.I_lhs).Add(Gfh_tag_.B_lhs); break;
case Xop_apos_tkn_.Cmd_bi_end: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_rhs);; break;
case Xop_apos_tkn_.Cmd_bi_end__b_bgn: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_lhs); break;
case Xop_apos_tkn_.Cmd_ib_end__i_bgn: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_lhs); break;
case Xop_apos_tkn_.Cmd_b_end__i_bgn: bfr.Add(Gfh_tag_.B_rhs).Add(Gfh_tag_.I_lhs); break;
case Xop_apos_tkn_.Cmd_i_end__b_bgn: bfr.Add(Gfh_tag_.I_rhs).Add(Gfh_tag_.B_lhs); break;
case Xop_apos_tkn_.Cmd_nil: break;
default: throw Err_.new_unhandled(apos.Apos_cmd());
}
@@ -466,9 +466,9 @@ public class Xoh_html_wtr {
break;
default:
byte[] tag_name = sub_xnde.Tag().Name_bry();
bfr.Add(Html_entity_.Lt_bry).Add(tag_name);
bfr.Add(Gfh_entity_.Lt_bry).Add(tag_name);
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(sub_xnde.Tag().Id(), hctx, src, sub_xnde.Atrs_bgn(), sub_xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
bfr.Add(Html_entity_.Gt_bry);
bfr.Add(Gfh_entity_.Gt_bry);
break;
}
Xnde_subs_escape(ctx, hctx, bfr, src, sub_xnde, amp_enable, false);

View File

@@ -40,17 +40,17 @@ public class Xoh_html_wtr_escaper {
}
}
}
bfr.Add(Html_entity_.Lt_bry);
bfr.Add(Gfh_entity_.Lt_bry);
break;
case Byte_ascii.Gt:
bfr.Add(Html_entity_.Gt_bry);
bfr.Add(Gfh_entity_.Gt_bry);
break;
case Byte_ascii.Amp:
if (interpret_amp) {
int text_bgn = i + 1; // i is &; i + 1 is first char after amp
Object o = (text_bgn < end) ? amp_trie.Match_bgn(src, text_bgn, end) : null; // check if this is a valid &; note must check that text_bgn < end or else arrayIndex error; occurs when src is just "&"; DATE:2013-12-19
if (o == null) // invalid; EX: "a&b"; "&bad;"; "&#letters;";
bfr.Add(Html_entity_.Amp_bry); // escape & and continue
bfr.Add(Gfh_entity_.Amp_bry); // escape & and continue
else { // is either (1) a name or (2) an ncr (hex/dec)
Xop_amp_trie_itm itm = (Xop_amp_trie_itm)o;
int match_pos = amp_trie.Match_pos();
@@ -70,17 +70,17 @@ public class Xoh_html_wtr_escaper {
i = end_pos - 1;
}
else // parse failed; escape and continue
bfr.Add(Html_entity_.Amp_bry);
bfr.Add(Gfh_entity_.Amp_bry);
break;
default: throw Err_.new_unhandled(itm_tid);
}
}
}
else
bfr.Add(Html_entity_.Amp_bry);
bfr.Add(Gfh_entity_.Amp_bry);
break;
case Byte_ascii.Quote:
bfr.Add(Html_entity_.Quote_bry);
bfr.Add(Gfh_entity_.Quote_bry);
break;
default:
bfr.Add_byte(b);
@@ -103,7 +103,7 @@ public class Xoh_html_wtr_escaper {
if ( tag_is_bgn // <nowiki < found
|| (i + nowiki_name_len + 2 > end) // not enough chars for "/nowiki>"
|| src[i + 1] != Byte_ascii.Slash // /
|| !Bry_.Eq(src, i + 2, i + 2 + nowiki_name_len, nowiki_name) // nowiki
|| !Bry_.Eq(src, i + 2, i + 2 + nowiki_name_len, nowiki_name) // nowiki
|| src[i + 2 + nowiki_name_len] != Byte_ascii.Gt // >
) return Bry_find_.Not_found;
end_lt = i;

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import org.junit.*;
public class Xoh_html_wtr_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_(); fxt.Reset();}
@Test public void Hr_basic() {fxt.Test_parse_page_wiki_str("----" , "<hr/>");}
@Test public void Hr_extended() {fxt.Test_parse_page_wiki_str("--------" , "<hr/>");}

View File

@@ -65,9 +65,9 @@ public class Xoh_tidy_mgr implements GfoInvkAble {
}
public static boolean Tidy_unwrap(Bry_bfr bfr) {
byte[] bfr_bry = bfr.Bfr();
int find = Bry_find_.Find_fwd(bfr_bry, Html_tag_.Body_lhs); if (find == Bry_find_.Not_found) return false;
bfr.Delete_rng_to_bgn(find + Html_tag_.Body_lhs.length);
find = Bry_find_.Find_bwd(bfr_bry, Html_tag_.Body_rhs, bfr.Len()); if (find == Bry_find_.Not_found) return false;
int find = Bry_find_.Find_fwd(bfr_bry, Gfh_tag_.Body_lhs); if (find == Bry_find_.Not_found) return false;
bfr.Delete_rng_to_bgn(find + Gfh_tag_.Body_lhs.length);
find = Bry_find_.Find_bwd(bfr_bry, Gfh_tag_.Body_rhs, bfr.Len()); if (find == Bry_find_.Not_found) return false;
bfr.Delete_rng_to_end(find);
return true;
}

View File

@@ -38,7 +38,7 @@ public class Xoh_anchor_kv_bldr {
tmp_bfr.Add_byte(has_qarg ? Byte_ascii.Amp : Byte_ascii.Question);
tmp_bfr.Add(key);
tmp_bfr.Add_byte(Byte_ascii.Eq);
tmp_bfr.Add(Html_utl.Escape_for_atr_val_as_bry(apos_bfr, Byte_ascii.Apos, bry));
tmp_bfr.Add(Gfh_utl.Escape_for_atr_val_as_bry(apos_bfr, Byte_ascii.Apos, bry));
return this;
}
public byte[] Bld_to_bry() {

View File

@@ -32,7 +32,7 @@ public class Xoh_lnki_bldr {
img_pos_is_left = true;
return this;
}
public Xoh_lnki_bldr Id_(byte[] v) {this.id = Html_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, v); return this;}
public Xoh_lnki_bldr Id_(byte[] v) {this.id = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, v); return this;}
public Xoh_lnki_bldr Href_(Xow_wiki wiki, byte[] bry) {return Href_(wiki.Domain_bry(), wiki.Ttl_parse(bry));}
public Xoh_lnki_bldr Href_(byte[] domain_bry, Xoa_ttl ttl) {
href_wtr.Build_to_bfr(tmp_bfr, app, Xoh_wtr_ctx.Mode_popup, domain_bry, ttl);
@@ -40,7 +40,7 @@ public class Xoh_lnki_bldr {
return this;
}
public Xoh_lnki_bldr Title_(byte[] title) {
this.title = Html_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, title);
this.title = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, Byte_ascii.Apos, title);
return this;
}
public Xoh_lnki_bldr Img_pos_is_left_(boolean v) {this.img_pos_is_left = v; return this;}
@@ -52,7 +52,7 @@ public class Xoh_lnki_bldr {
return this;
}
public Xoh_lnki_bldr Caption_(byte[] text) {
this.caption = Html_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y);
this.caption = Gfh_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y);
return this;
}
public byte[] Bld_to_bry() {

View File

@@ -29,6 +29,6 @@ public class Xoh_lnki_wtr_utl {
return tmp_bfr.To_bry_and_clear();
}
public byte[] Bld_title(byte[] text) {
return gplx.langs.htmls.Html_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.Y);
return gplx.langs.htmls.Gfh_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.Y);
}
}

View File

@@ -0,0 +1,81 @@
/*
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.core.primitives.*; import gplx.core.encoders.*;
public class Gfo_decimal_parser {
public boolean Sign() {return sign;} private boolean sign;
public int Exponent() {return exponent;} private int exponent;
public long Number() {return number;} private long number;
public boolean Parse(byte[] src, int src_bgn, int src_end) {
sign = true;
number = 0;
exponent = 0;
if (src_end - src_bgn < 1) return false;
int pos = src_bgn;
int dot_offset = 0;
byte b = Byte_ascii.Null;
boolean loop = true;
while (loop) {
b = src[pos++];
switch (b) {
case Byte_ascii.Dash:
if (!sign) return false; // fail if "--"
sign = false; // keep looping; handle "-0.12"
++dot_offset;
break;
case Byte_ascii.Num_0:
b = src[pos++];
if (b != Byte_ascii.Dot) return false; // fail if not "0."
++dot_offset;
loop = false;
break;
default:
loop = false;
break;
}
}
int dot_pos = -1;
boolean num_seen = false;
while (true) {
switch (b) {
case Byte_ascii.Dot:
if (dot_pos != -1) return false; // fail if multiple dots
dot_pos = pos - src_bgn - dot_offset - 1; // pos already advanced forward one
break;
case Byte_ascii.Num_0:
if (num_seen)
number *= 10;
break;
case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
if (!num_seen) num_seen = true; // save first "number"; for "0.00001" where num will be 0 and left shift will be 5
number *= 10;
number += b - Byte_ascii.Num_0;
break;
}
if (pos == src_end) break;
b = src[pos];
++pos;
}
switch (dot_pos) {
case -1: exponent = 0; break;
default: exponent = dot_pos + dot_offset - src_end + 1; break;
}
return true;
}
}

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.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import org.junit.*;
public class Gfo_decimal_parser_tst {
private final Gfo_decimal_parser_fxt fxt = new Gfo_decimal_parser_fxt();
@Test public void Positive() {
fxt.Test__parse("123" , Bool_.Y, 0, 123);
fxt.Test__parse("12.3" , Bool_.Y, -1, 123);
fxt.Test__parse("1.23" , Bool_.Y, -2, 123);
fxt.Test__parse(".123" , Bool_.Y, -3, 123);
fxt.Test__parse("0.123" , Bool_.Y, -3, 123);
}
@Test public void Negative() {
fxt.Test__parse("-123" , Bool_.N, 0, 123);
fxt.Test__parse("-12.3" , Bool_.N, -1, 123);
fxt.Test__parse("-1.23" , Bool_.N, -2, 123);
fxt.Test__parse("-.123" , Bool_.N, -3, 123);
fxt.Test__parse("-0.123" , Bool_.N, -3, 123);
}
}
class Gfo_decimal_parser_fxt {
private final Gfo_decimal_parser bicoder = new Gfo_decimal_parser();
public void Test__parse(String src_str, boolean expd_sign, int expd_exponent, long expd_number) {
byte[] src_bry = Bry_.new_u8(src_str);
bicoder.Parse(src_bry, 0, src_bry.length);
Tfds.Eq_bool(expd_sign, bicoder.Sign());
Tfds.Eq_int(expd_exponent, bicoder.Exponent());
Tfds.Eq_long(expd_number, bicoder.Number());
}
}

View File

@@ -0,0 +1,27 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
import gplx.xowa.htmls.core.wkrs.*; import gplx.core.threads.poolables.*;
public interface Xoh_data_itm extends Gfo_poolable_itm {
int Tid();
int Src_bgn();
int Src_end();
void Clear();
boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag cur, Gfh_tag nxt);
}

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.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_decimal {
private final Gfo_decimal_parser decimal_parser = new Gfo_decimal_parser();
public boolean Encode(Bry_bfr bfr, byte[] src, int src_bgn, int src_end) {
if (!decimal_parser.Parse(src, src_bgn, src_end)) return false;
// if (positive && dot_pos == -1 && num_val < 128) {
// bfr.Add_byte((byte)(num_val + 128));
// }
return true;
/*
0.001000
1:size_is_1
1:exp.neg
6:exp.val
5:exp.val
1:num.neg
7:num.val; 111-127 for extended bits
8:num.val
8:num.val
127
125 2
126 3
127 4
*/
}
}

View File

@@ -18,8 +18,20 @@ 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.*;
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
public static final byte Escape = Byte_.By_int(27); // SERIALIZED: 27=escape byte
public static final byte[] Escape_bry = Bry_.New_by_ints(27); // SERIALIZED
public static final int
Tid__root = 0
, Tid__escape = 1
, Tid__xnde = 2
, Tid__lnke = 3
, Tid__lnki = 4
, Tid__hdr = 5
, Tid__img = 6
, Tid__thm = 7
, Tid__gly = 8
, Tid__img_bare = 9
;
public static final String
Key__escape = "escape"
, Key__hdr = "hdr"
@@ -29,6 +41,7 @@ public class Xoh_hzip_dict_ {
, Key__thm = "thm"
, Key__gly = "gly"
, Key__xnde = "xnde"
, Key__img_bare = "img_bare"
;
public static final int Hzip__none = 0, Hzip__v1 = 1;
}

View File

@@ -126,7 +126,7 @@ public class Xoh_hzip_int {
val -= tmp * div;
}
}
private static int To_int_by_bry(byte[] src, int bgn, int end, byte offset, int radix) {
public static int To_int_by_bry(byte[] src, int bgn, int end, byte offset, int radix) {
int rv = 0, factor = 1;
for (int i = end - 1; i >= bgn; --i) {
rv += ((src[i] & 0xFF) - offset) * factor; // PATCH.JAVA:need to convert to unsigned byte
@@ -140,7 +140,7 @@ public class Xoh_hzip_int {
, B256__max__expd__3 = 16777216 // 16,777,216
;
private static final int[] B256__pow__ary = new int[] {1, B256__max__expd__1, B256__max__expd__2, B256__max__expd__3, Int_.Max_value};
private static final byte prefix__b256__2 = (byte)(252 & 0xFF), prefix__b256__3 = (byte)(253 & 0xFF), prefix__b256__4 = (byte)(254 & 0xFF), prefix__b256__5 = (byte)(255 & 0xFF);
public static final byte prefix__b256__2 = (byte)(252 & 0xFF), prefix__b256__3 = (byte)(253 & 0xFF), prefix__b256__4 = (byte)(254 & 0xFF), prefix__b256__5 = (byte)(255 & 0xFF);
private static final byte[]
prefix_ary__b256 = new byte[] {0, 0, prefix__b256__2, prefix__b256__3, prefix__b256__4, prefix__b256__5}
, prefix_ary__b085 = new byte[] {0, 0, 0, Byte_ascii.Curly_bgn, Byte_ascii.Pipe, Byte_ascii.Curly_end, Byte_ascii.Tilde}

View File

@@ -17,19 +17,20 @@ 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.core.threads.poolables.*;
import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.wikis.ttls.*;
public class Xoh_hzip_mgr implements Xoh_hzip_wkr {
private final Xoh_hdoc_wkr hdoc_wkr = new Xoh_hdoc_wkr__hzip();
private final Xoh_hdoc_parser hdoc_parser;
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Xoh_hzip_dict_.Escape);
public Xoh_hzip_mgr() {this.hdoc_parser = new Xoh_hdoc_parser(hdoc_wkr);}
public int Tid() {return Xoh_hzip_dict_.Tid__lnke;}
public String Key() {return "root";}
public byte[] Hook() {return hook;} private byte[] hook;
public Xoh_hdoc_ctx Hctx() {return hctx;} private final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx();
public void Init_by_app(Xoa_app app) {hctx.Init_by_app(app);}
public byte[] Encode_as_bry(Xoh_hzip_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src) {Encode(bfr, wiki, hpg, src); return bfr.To_bry_and_clear();}
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {throw Err_.new_unimplemented();}
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {throw Err_.new_unimplemented();}
public void Encode(Xoh_hzip_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src) {
hctx.Init_by_page(wiki, hpg.Url_bry_safe());
hdoc_parser.Parse(bfr, hpg, hctx, src);
@@ -38,14 +39,14 @@ public class Xoh_hzip_mgr implements Xoh_hzip_wkr {
byte[] page_url = hpg.Url_bry_safe(); int src_len = src.length;
hctx.Init_by_page(wiki, page_url);
rdr.Init_by_page(page_url, src, src_len);
Decode(bfr, hdoc_wkr, hctx, hpg, Bool_.Y, rdr, src, 0, src_len);
Decode1(bfr, hdoc_wkr, hctx, hpg, rdr, src, 0, src_len, null);
}
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
int pos = src_bgn, txt_bgn = -1;
while (true) {
if (pos == src_end) break;
byte b = src[pos];
Object o = hctx.Wkr_mkr().Get(b, src, pos, src_end);
Object o = hctx.Pool_mgr__hzip().Get(b, src, pos, src_end);
if (o == null) {
if (txt_bgn == -1) txt_bgn = pos;
++pos;
@@ -53,19 +54,27 @@ public class Xoh_hzip_mgr implements Xoh_hzip_wkr {
else {
if (txt_bgn != -1) {bfr.Add_mid(src, txt_bgn, pos); txt_bgn = -1;} // handle pending txt
Xoh_hzip_wkr wkr = (Xoh_hzip_wkr)o;
int hook_len = wkr.Hook().length;
try {
rdr.Init_by_sect(wkr.Key(), pos, pos + 2);
wkr.Decode(bfr, hdoc_wkr, hctx, hpg, Bool_.Y, rdr, src, pos, src_end);
rdr.Init_by_sect(wkr.Key(), pos, pos + hook_len);
Xoh_data_itm data = hctx.Pool_mgr__data().Get_by_tid(wkr.Tid());
wkr.Decode1(bfr, hdoc_wkr, hctx, hpg, rdr, src, pos, src_end, data);
Xoh_wtr_itm wtr = hctx.Pool_mgr__wtr().Get_by_tid(wkr.Tid());
if (data != null && wtr != null) {
wtr.Init_by_decode(hpg, hctx, src, data);
wtr.Bfr_arg__add(bfr);
}
if (data != null) data.Pool__rls();
if (wtr != null) wtr.Pool__rls();
pos = rdr.Pos();
} catch (Exception e) {
gplx.langs.htmls.Html_utl.Log(e, "hzip decode failed", hpg.Url_bry_safe(), src, pos);
pos += 2; // 2: skip escape and hook
gplx.langs.htmls.Gfh_utl.Log(e, "hzip decode failed", hpg.Url_bry_safe(), src, pos);
pos += hook_len;
}
finally {wkr.Pool__rls();}
}
}
if (txt_bgn != -1) bfr.Add_mid(src, txt_bgn, src_end);
return src_end;
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hzip_mgr rv = new Xoh_hzip_mgr(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}

View File

@@ -19,8 +19,9 @@ package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gp
import gplx.core.brys.*; import gplx.core.threads.poolables.*;
import gplx.xowa.htmls.core.wkrs.*;
public interface Xoh_hzip_wkr extends gplx.core.threads.poolables.Gfo_poolable_itm {
int Tid();
String Key();
byte[] Hook();
Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj);
int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end);
Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj);
void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm);
}

View File

@@ -0,0 +1,47 @@
/*
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.core.btries.*; import gplx.core.threads.poolables.*;
import gplx.xowa.htmls.core.wkrs.escapes.*;
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.xndes.*;
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.glys.*;
public class Xoh_pool_mgr__data {
private final Gfo_poolable_mgr pool__hdr, pool__lnke, pool__img, pool__img_bare;//, pool__gly;
public Xoh_pool_mgr__data() {
pool__hdr = New_pool(new Xoh_hdr_data());
pool__lnke = New_pool(new Xoh_lnke_data());
pool__img = New_pool(new Xoh_img_data());
pool__img_bare = New_pool(new Xoh_img_bare_data());
// pool__gly = New_pool(new Xoh_gly_grp_data());
}
public Xoh_data_itm Get_by_tid(int tid) {
Gfo_poolable_mgr pool = null;
switch (tid) {
case Xoh_hzip_dict_.Tid__hdr: pool = pool__hdr; break;
case Xoh_hzip_dict_.Tid__lnke: pool = pool__lnke; break;
case Xoh_hzip_dict_.Tid__img: pool = pool__img; break;
case Xoh_hzip_dict_.Tid__img_bare: pool = pool__img_bare; break;
// case Xoh_hzip_dict_.Tid__gly: pool = pool__gly; break;
default: return null;
}
return (Xoh_data_itm)pool.Get_fast();
}
private static Gfo_poolable_mgr New_pool(Gfo_poolable_itm proto) {
return Gfo_poolable_mgr_.New(1, 32, proto);
}
}

View File

@@ -18,41 +18,50 @@ 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.btries.*; import gplx.core.threads.poolables.*;
import gplx.xowa.htmls.core.wkrs.escapes.*;
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.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.xndes.*;
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.glys.*;
public class Xoh_hzip_wkr_mgr {
public class Xoh_pool_mgr__hzip {
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
private Gfo_poolable_mgr mkr__escape, mkr__lnke, mkr__lnki, mkr__hdr, mkr__img, mkr__thm, mkr__gly;
private Gfo_poolable_mgr mkr__escape, mkr__xnde, mkr__lnke, mkr__lnki, mkr__hdr, mkr__img, mkr__thm, mkr__gly, mkr__img_bare;
public Xoh_escape_hzip Mw__escape() {return (Xoh_escape_hzip) mkr__escape.Get_fast();}
public Xoh_xnde_hzip Mw__xnde() {return (Xoh_xnde_hzip) mkr__xnde.Get_fast();}
public Xoh_hdr_hzip Mw__hdr() {return (Xoh_hdr_hzip) mkr__hdr.Get_fast();}
public Xoh_lnke_hzip Mw__lnke() {return (Xoh_lnke_hzip) mkr__lnke.Get_fast();}
public Xoh_lnki_hzip Mw__lnki() {return (Xoh_lnki_hzip) mkr__lnki.Get_fast();}
public Xoh_img_hzip Mw__img() {return (Xoh_img_hzip) mkr__img.Get_fast();}
public Xoh_img_bare_hzip Mw__img_bare() {return (Xoh_img_bare_hzip) mkr__img_bare.Get_fast();}
public Xoh_thm_hzip Mw__thm() {return (Xoh_thm_hzip) mkr__thm.Get_fast();}
public Xoh_gly_hzip Mw__gly() {return (Xoh_gly_hzip) mkr__gly.Get_fast();}
public void Init() {
this.Reg_all(false, Byte_ascii.Escape);
this.Reg_all(false, Hook__core, Hook__html, Hook__mw);
}
public Xoh_hzip_wkr Get(byte b, byte[] src, int src_bgn, int src_end) {
Object mgr_obj = trie.Match_bgn_w_byte(b, src, src_bgn, src_end); if (mgr_obj == null) return null;
Gfo_poolable_mgr mgr = (Gfo_poolable_mgr)mgr_obj;
return (Xoh_hzip_wkr)mgr.Get_fast();
}
private void Reg_all(boolean mode_is_b256, int escape__mw) {
mkr__escape = Reg(New_hook_len2(mode_is_b256, escape__mw, 84), new Xoh_escape_hzip());
mkr__hdr = Reg(New_hook_len2(mode_is_b256, escape__mw, 1), new Xoh_hdr_hzip());
mkr__lnke = Reg(New_hook_len2(mode_is_b256, escape__mw, 2), new Xoh_lnke_hzip());
mkr__lnki = Reg(New_hook_len2(mode_is_b256, escape__mw, 3), new Xoh_lnki_hzip());
mkr__img = Reg(New_hook_len2(mode_is_b256, escape__mw, 4), new Xoh_img_hzip());
mkr__thm = Reg(New_hook_len2(mode_is_b256, escape__mw, 5), new Xoh_thm_hzip());
mkr__gly = Reg(New_hook_len2(mode_is_b256, escape__mw, 6), new Xoh_gly_hzip());
private void Reg_all(boolean mode_is_b256, int hook__core, int hook__html, int hook__mw) {
mkr__escape = Reg(New_hook_len2(mode_is_b256, hook__core, 0) , new Xoh_escape_hzip());
mkr__xnde = Reg(New_hook_len1(mode_is_b256, hook__html) , new Xoh_xnde_hzip());
mkr__hdr = Reg(New_hook_len2(mode_is_b256, hook__mw , 1) , new Xoh_hdr_hzip());
mkr__lnke = Reg(New_hook_len2(mode_is_b256, hook__mw , 2) , new Xoh_lnke_hzip());
mkr__lnki = Reg(New_hook_len2(mode_is_b256, hook__mw , 3) , new Xoh_lnki_hzip());
mkr__img = Reg(New_hook_len2(mode_is_b256, hook__mw , 4) , new Xoh_img_hzip());
mkr__thm = Reg(New_hook_len2(mode_is_b256, hook__mw , 5) , new Xoh_thm_hzip());
mkr__gly = Reg(New_hook_len2(mode_is_b256, hook__mw , 6) , new Xoh_gly_hzip());
mkr__img_bare = Reg(New_hook_len2(mode_is_b256, hook__mw , 7) , new Xoh_img_bare_hzip());
}
private Gfo_poolable_mgr Reg(byte[] hook, Gfo_poolable_itm proto) {
Gfo_poolable_mgr rv = Gfo_poolable_mgr_.New(1, 32, proto, Object_.Ary(hook));
trie.Add_obj(hook, rv);
return rv;
}
private static byte[] New_hook_len2(boolean mode_is_b256, int b0, int b1) {
return Bry_.new_ints(b0, mode_is_b256 ? b1 : b1 + Byte_ascii.Bang);
}
private static byte[] New_hook_len2(boolean mode_is_b256, int b0, int b1) {return Bry_.New_by_ints(b0, mode_is_b256 ? b1 : b1 + Byte_ascii.Bang);}
private static byte[] New_hook_len1(boolean mode_is_b256, int b0) {return Bry_.New_by_ints(b0);}
public static final byte
Hook__core = 1
, Hook__html = 2
, Hook__mw = 27
;
public static final byte[] Hooks_ary = new byte[] {Hook__core, Hook__html, Hook__mw};
}

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.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.core.brys.*; import gplx.core.threads.poolables.*;
import gplx.xowa.htmls.core.wkrs.escapes.*;
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.xndes.*;
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.glys.*;
public class Xoh_pool_mgr__wtr {
private final Gfo_poolable_mgr pool__hdr, pool__lnke, pool__img, pool__img_bare;
public Xoh_pool_mgr__wtr() {
pool__hdr = New_pool(new Xoh_hdr_wtr());
pool__lnke = New_pool(new Xoh_lnke_wtr());
pool__img = New_pool(new Xoh_img_wtr());
pool__img_bare = New_pool(new Xoh_img_bare_wtr());
}
public Xoh_wtr_itm Get_by_tid(int tid) {
Gfo_poolable_mgr pool = null;
switch (tid) {
case Xoh_hzip_dict_.Tid__hdr: pool = pool__hdr; break;
case Xoh_hzip_dict_.Tid__lnke: pool = pool__lnke; break;
case Xoh_hzip_dict_.Tid__img: pool = pool__img; break;
case Xoh_hzip_dict_.Tid__img_bare: pool = pool__img_bare; break;
default: return null;
}
return (Xoh_wtr_itm)pool.Get_fast();
}
private static Gfo_poolable_mgr New_pool(Gfo_poolable_itm proto) {
return Gfo_poolable_mgr_.New(1, 32, proto);
}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.core.brys.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
import gplx.xowa.htmls.core.wkrs.*; import gplx.core.threads.poolables.*;
public interface Xoh_wtr_itm extends Bfr_arg, Gfo_poolable_itm {
boolean Init_by_decode(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_data_itm data_itm);
}

View File

@@ -100,33 +100,33 @@ public class Xoh_make_mgr {
byte[] a_href = Bry_.Add(Xoh_make_trie_.A_href_bgn, a_title);
try {
switch (tid) {
case Xoh_make_trie_.Tid__file_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, cfg_file.Img_media_info_btn()); return rv;
case Xoh_make_trie_.Tid__file_info: fmtr.Html_thumb_part_info (bfr, uid, true, a_href, cfg_file.Img_media_info_btn()); return rv;
case Xoh_make_trie_.Tid__file_mgnf: fmtr.Html_thumb_part_magnify(bfr, uid, a_href, a_title, cfg_file.Img_thumb_magnify()); return rv;
case Xoh_make_trie_.Tid__file_play: fmtr.Html_thumb_part_play (bfr, uid, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, cfg_file.Img_media_play_btn()); return rv;
case Xoh_make_trie_.Tid__file_play: fmtr.Html_thumb_part_play (bfr, uid, true, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, cfg_file.Img_media_play_btn()); return rv;
case Xoh_make_trie_.Tid__gallery_box_max: {
Xohd_img_itm__gallery_mgr gly = (Xohd_img_itm__gallery_mgr)hpg.Gallery_itms().Get_by(uid);
if (gly != null) { // -1 means no box_max
byte[] style = Gallery_mgr_base.box_style_max_width_fmtr.Bld_bry_many(tmp_bfr, gly.Box_max());
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Bry__style, style);
byte[] style = Gallery_html_wtr_.Fmtr__ul__style.Bld_bry_many(tmp_bfr, gly.Box_max());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
}
return rv;
}
case Xoh_make_trie_.Tid__gallery_box_w: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_mgr_base.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Box_w());
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Bry__style, style);
byte[] style = Gallery_html_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Box_w());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}
case Xoh_make_trie_.Tid__gallery_img_w: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_mgr_base.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Img_w());
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Bry__style, style);
byte[] style = Gallery_html_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Img_w());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}
case Xoh_make_trie_.Tid__gallery_img_pad: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_mgr_base.hdump_img_pad_fmtr.Bld_bry_many(tmp_bfr, gly.Img_pad());
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Bry__style, style);
byte[] style = Gallery_html_wtr_.hdump_img_pad_fmtr.Bld_bry_many(tmp_bfr, gly.Img_pad());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}
}

View File

@@ -30,7 +30,7 @@ public class Xoh_make_trie_ {
, 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__hiero_dir = Bry_.new_a7("~{xowa_hiero_dir}")
// , Bry__hiero_dir = Bry_.new_a7("~{xowa_hiero_dir}")
// , Bry__gallery_box_max = Bry_.new_a7("xowa_gly_box_max='")
// , Bry__gallery_box_w = Bry_.new_a7("xowa_gly_box_w='")
// , Bry__gallery_img_w = Bry_.new_a7("xowa_gly_img_w='")
@@ -50,7 +50,7 @@ public class Xoh_make_trie_ {
trie_itm(rv, Tid__file_play , Byte_ascii.Apos , Bry__file_play);
trie_itm(rv, Tid__file_info , Byte_ascii.Apos , Bry__file_info);
trie_itm(rv, Tid__file_mgnf , Byte_ascii.Apos , Bry__file_mgnf);
trie_itm(rv, Tid__hiero_dir , Byte_ascii.Escape , Bry__hiero_dir);
// trie_itm(rv, Tid__hiero_dir , Byte_ascii.Escape , Bry__hiero_dir);
// trie_itm(rv, Tid__gallery_box_max , Byte_ascii.Apos , Bry__gallery_box_max);
// trie_itm(rv, Tid__gallery_box_w , Byte_ascii.Apos , Bry__gallery_box_w);
// trie_itm(rv, Tid__gallery_img_w , Byte_ascii.Apos , Bry__gallery_img_w);

View File

@@ -37,7 +37,8 @@ public class Xoh_make_fxt {
}
public void Test__html(String wtxt, String expd) {
expd = String_.Replace(expd, "'", "\"");
Tfds.Eq_str_lines(expd, parser_fxt.Exec__parse_to_hdump(wtxt));
String actl = parser_fxt.Exec__parse_to_hdump(wtxt);
Tfds.Eq_str_lines(expd, actl);
}
public void Test__make(String html, Xoh_page_chkr chkr) {
html = String_.Replace(html, "'", "\"");

View File

@@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.xowa.apps.urls.*;
import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.xndes.tags.*; import gplx.xowa.htmls.core.wkrs.xndes.dicts.*;
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.apps.metas.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.apps.metas.*;
public class Xoh_hdoc_ctx {
private byte[] fsys__file;
public byte[] Fsys__root() {return fsys__root;} private byte[] fsys__root;
@@ -32,10 +32,15 @@ public class Xoh_hdoc_ctx {
public boolean Xwiki_mgr__missing(byte[] domain){return app.Xwiki_mgr__missing(domain);}
public Xoa_file_mgr File__mgr() {return file__mgr;} private final Xoa_file_mgr file__mgr = new Xoa_file_mgr();
public Xof_url_bldr File__url_bldr() {return file__url_bldr;} private final Xof_url_bldr file__url_bldr = new Xof_url_bldr();
public Xoh_hzip_wkr_mgr Wkr_mkr() {return wkr_mgr;} private final Xoh_hzip_wkr_mgr wkr_mgr = new Xoh_hzip_wkr_mgr();
public byte[] Page__url() {return page__url;} private byte[] page__url;
public Xoh_pool_mgr__hzip Pool_mgr__hzip() {return pool_mgr__hzip;} private final Xoh_pool_mgr__hzip pool_mgr__hzip = new Xoh_pool_mgr__hzip();
public Xoh_pool_mgr__data Pool_mgr__data() {return pool_mgr__data;} private final Xoh_pool_mgr__data pool_mgr__data = new Xoh_pool_mgr__data();
public Xoh_pool_mgr__wtr Pool_mgr__wtr() {return pool_mgr__wtr;} private final Xoh_pool_mgr__wtr pool_mgr__wtr = new Xoh_pool_mgr__wtr();
public Xoh_stat_itm Hzip__stat() {return hzip__stat;} private final Xoh_stat_itm hzip__stat = new Xoh_stat_itm();
public int Lnki__uid__nxt() {return ++lnki__uid;} private int lnki__uid; // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
public Xohz_tag_regy Hzip__xnde__regy() {return hzip__xnde__regy;} private final Xohz_tag_regy hzip__xnde__regy = Xohz_tag_regy_.New_dflt();
public Xoh_xnde_dict_reg Hzip__xnde__dict() {return hzip__xnde__dict;} private final Xoh_xnde_dict_reg hzip__xnde__dict = new Xoh_xnde_dict_reg();
public int Uid__lnki_nxt() {return ++uid__lnki;} private int uid__lnki;
public int Uid__gly__nxt() {return ++uid__gly;} private int uid__gly;
public boolean Mode_is_diff() {return mode_is_diff;} private boolean mode_is_diff; public void Mode_is_diff_(boolean v) {mode_is_diff = v;}
public void Init_by_app(Xoa_app app) {
Xoa_fsys_mgr fsys_mgr = app.Fsys_mgr();
@@ -43,7 +48,7 @@ public class Xoh_hdoc_ctx {
this.fsys__root = fsys_mgr.Root_dir().To_http_file_bry();
this.fsys__file = fsys_mgr.File_dir().To_http_file_bry();
this.fsys__file__comm = Bry_.Add(fsys__file, Xow_domain_itm_.Bry__commons, Byte_ascii.Slash_bry);
wkr_mgr.Init();
pool_mgr__hzip.Init();
}
public void Init_by_page(Xow_wiki wiki, byte[] page_url) {
if (fsys__root == null) Init_by_app(wiki.App()); // LAZY INIT
@@ -56,7 +61,8 @@ public class Xoh_hdoc_ctx {
}
private void Clear() {
hzip__stat.Clear();
this.lnki__uid = 1; // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
this.uid__lnki = 1; // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
this.uid__gly = -1;
}
public static final int Invalid = -1;
}

View File

@@ -16,19 +16,22 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.langs.htmls.docs.*; import gplx.xowa.wikis.ttls.*;
import gplx.xowa.htmls.core.makes.*; 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.hzips.*;
public class Xoh_hdoc_parser {
private final Xoh_hdoc_wkr hdoc_wkr;
private final Html_doc_parser hdoc_parser;
private final Gfh_doc_parser hdoc_parser;
private final Xoh_tag_parser tag_parser;
public Xoh_hdoc_parser(Xoh_hdoc_wkr hdoc_wkr) {
this.hdoc_wkr = hdoc_wkr;
this.tag_parser = new Xoh_tag_parser(hdoc_wkr);
this.hdoc_parser = new Html_doc_parser(new Xoh_txt_parser(hdoc_wkr)
, tag_parser
, new Xoh_escape_data(hdoc_wkr)
);
int wkr_ary_len = Xoh_pool_mgr__hzip.Hooks_ary.length + 1;
Gfh_doc_wkr[] wkr_ary = new Gfh_doc_wkr[wkr_ary_len];
wkr_ary[0] = tag_parser;
for (int i = 1; i < wkr_ary_len; ++i)
wkr_ary[i] = new Xoh_escape_data(hdoc_wkr, Xoh_pool_mgr__hzip.Hooks_ary[i - 1]);
this.hdoc_parser = new Gfh_doc_parser(new Xoh_txt_parser(hdoc_wkr), wkr_ary);
}
public void Parse(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src) {
int src_len = src.length;

View File

@@ -16,16 +16,16 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.langs.htmls.parsers.*;
import gplx.langs.htmls.docs.*;
import gplx.xowa.wikis.ttls.*;
import gplx.xowa.htmls.core.hzips.*;
public interface Xoh_hdoc_wkr {
void On_new_page(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end);
void On_escape (int rng_bgn, int rng_end);
void On_txt (int rng_bgn, int rng_end);
void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser parser);
void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser parser);
void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser parser);
void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser parser);
void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser parser);
void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser parser);
void On_escape (gplx.xowa.htmls.core.wkrs.escapes.Xoh_escape_data data);
void On_xnde (gplx.xowa.htmls.core.wkrs.xndes.Xoh_xnde_parser parser);
void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_data parser);
void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data parser);
void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data parser);
boolean Process_parse(Xoh_data_itm data);
}

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; 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.langs.htmls.docs.*; import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.wikis.ttls.*;
public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
private final Xoh_stat_itm stat_itm = new Xoh_stat_itm();
@@ -27,11 +27,21 @@ public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
stat_itm.Clear();
}
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
public void On_escape (int rng_bgn, int rng_end) {hctx.Wkr_mkr().Mw__escape().Encode(bfr, this, hctx, hpg, Bool_.Y, src, null).Pool__rls();}
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser parser) {hctx.Wkr_mkr().Mw__hdr().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
public void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser parser) {hctx.Wkr_mkr().Mw__lnke().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser parser) {hctx.Wkr_mkr().Mw__lnki().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser parser) {hctx.Wkr_mkr().Mw__img().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser parser) {hctx.Wkr_mkr().Mw__thm().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser parser) {hctx.Wkr_mkr().Mw__gly().Encode(bfr, this, hctx, hpg, Bool_.Y, src, parser).Pool__rls();}
public void On_escape (gplx.xowa.htmls.core.wkrs.escapes.Xoh_escape_data data) {hctx.Pool_mgr__hzip().Mw__escape().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
public void On_xnde (gplx.xowa.htmls.core.wkrs.xndes.Xoh_xnde_parser data) {hctx.Pool_mgr__hzip().Mw__xnde().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_data data) {hctx.Pool_mgr__hzip().Mw__lnki().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data data) {hctx.Pool_mgr__hzip().Mw__thm().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data data) {hctx.Pool_mgr__hzip().Mw__gly().Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();}
public boolean Process_parse(Xoh_data_itm data) {
Xoh_hzip_wkr wkr = null;
switch (data.Tid()) {
case Xoh_hzip_dict_.Tid__hdr: wkr = hctx.Pool_mgr__hzip().Mw__hdr(); break;
case Xoh_hzip_dict_.Tid__lnke: wkr = hctx.Pool_mgr__hzip().Mw__lnke(); break;
case Xoh_hzip_dict_.Tid__img: wkr = hctx.Pool_mgr__hzip().Mw__img(); break;
case Xoh_hzip_dict_.Tid__img_bare: wkr = hctx.Pool_mgr__hzip().Mw__img_bare(); break;
default: throw Err_.new_unhandled(data.Tid());
}
wkr.Encode1(bfr, this, hctx, hpg, Bool_.Y, src, data).Pool__rls();
return true;
}
}

View File

@@ -16,23 +16,31 @@ 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.langs.htmls.docs.*;
import gplx.xowa.wikis.ttls.*;
import gplx.xowa.htmls.core.hzips.*;
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 Xoh_hzip_bfr bfr; private Xoh_page hpg; private Xoh_hdoc_ctx hctx; private byte[] src;
private final Xoh_hdr_make wkr__hdr = new Xoh_hdr_make();
private final Xoh_img_bldr wkr__img = new Xoh_img_bldr();
private final Xoh_hdr_wtr wkr__hdr = new Xoh_hdr_wtr();
private final Xoh_img_wtr wkr__img = new Xoh_img_wtr();
public void On_new_page(Xoh_hzip_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
this.bfr = bfr; this.hpg = hpg; this.hctx = hctx; this.src = src;
}
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_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser parser) {bfr.Add_mid(src, parser.Src_bgn(), parser.Src_end());}
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser parser) {bfr.Add_mid(src, parser.Src_bgn(), parser.Src_end());}
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser parser) {wkr__hdr.Make(bfr, hpg, src, parser);}
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser parser) {wkr__img.Make_by_parse(bfr, hpg, hctx, src, parser);}
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser parser) {bfr.Add_mid(src, parser.Src_bgn(), parser.Src_end());}
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser parser) {}
public void On_escape (gplx.xowa.htmls.core.wkrs.escapes.Xoh_escape_data data) {bfr.Add(data.Hook());}
public void On_xnde (gplx.xowa.htmls.core.wkrs.xndes.Xoh_xnde_parser data) {bfr.Add_mid(src, data.Src_bgn(), data.Src_end());}
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_data data) {bfr.Add_mid(src, data.Src_bgn(), data.Src_end());}
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_data data) {bfr.Add_mid(src, data.Src_bgn(), data.Src_end());}
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_data data) {}
public boolean Process_parse(Xoh_data_itm data) {
switch (data.Tid()) {
case Xoh_hzip_dict_.Tid__img: wkr__img.Init_by_parse(bfr, hpg, hctx, src, (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_data)data); return true;
case Xoh_hzip_dict_.Tid__hdr: wkr__hdr.Init_by_parse(bfr, hpg, hctx, src, (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_data)data); return true;
case Xoh_hzip_dict_.Tid__lnke: break;
default: throw Err_.new_unhandled(data.Tid());
}
bfr.Add_mid(src, data.Src_bgn(), data.Src_end());
return true;
}
}

View File

@@ -44,8 +44,8 @@ public class Xoh_hzip_fxt {
}
public void Test__bicode(String hzip, String html) {Test__bicode(hzip, html, html);}
public void Test__bicode(String hzip, String html_enc, String html_dec) {
html_enc = Html_utl.Replace_apos(html_enc);
html_dec = Html_utl.Replace_apos(html_dec);
html_enc = Gfh_utl.Replace_apos(html_enc);
html_dec = Gfh_utl.Replace_apos(html_dec);
Test__bicode_raw(hzip, html_enc, html_dec);
}
public void Test__bicode_raw(String hzip, String html_enc, String html_dec) {
@@ -54,11 +54,11 @@ public class Xoh_hzip_fxt {
Test__decode__raw(hzip, html_dec);
}
public void Test__encode(String hzip, String html) {
hzip = Html_utl.Replace_apos(Xoh_hzip_fxt.Escape(hzip)); html = Html_utl.Replace_apos(html);
hzip = Xoh_hzip_fxt.Escape(hzip); html = Gfh_utl.Replace_apos(html);
Test__encode__raw(hzip, html);
}
public void Test__decode(String hzip, String html) {
hzip = Html_utl.Replace_apos(Xoh_hzip_fxt.Escape(hzip)); html = Html_utl.Replace_apos(html);
hzip = Xoh_hzip_fxt.Escape(hzip); html = Gfh_utl.Replace_apos(html);
Test__decode__raw(hzip, html);
}
public void Test__encode__fail(String expd, String html) {
@@ -73,6 +73,7 @@ public class Xoh_hzip_fxt {
}
private void Test__decode__raw(String hzip, String html) {
Gfo_usr_dlg_.Test__show__init();
hpg.Section_mgr().Clear();
hzip_mgr.Decode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(hzip));
Gfo_usr_dlg_.Test__show__term();
Tfds.Eq_str_lines(html, bfr.To_str_and_clear());
@@ -94,7 +95,7 @@ public class Xoh_hzip_fxt {
Gfo_usr_dlg_.Test__show__term();
Io_mgr.Instance.SaveFilBry(dir.GenSubFil(fil).GenNewExt(".hzip.decode.html"), bfr.To_bry_and_clear());
} catch (Exception e) {
Tfds.Write(e);
Tfds.Dbg(e);
}
}
public static String Escape(String v) {return String_.Replace(v, "~", "");}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.core.brys.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
public abstract class Xoh_itm_parser_fxt {
private final Xoae_app app;
private final Xowe_wiki wiki;

View File

@@ -16,14 +16,6 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
public class Bfr_arg__indent extends gplx.core.brys.Bfr_arg_base implements gplx.core.brys.Clear_able {
private int indent = 0;
public void Clear() {
this.indent = 0;
}
public void Set(int v) {this.indent = v;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
if (indent > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2);
}
public class Bfr_arg__hatr_ {
public static byte[] Bld_atr_bgn(byte[] key) {return Bry_.Add(Byte_ascii.Space_bry, key, Byte_ascii.Eq_bry, Byte_ascii.Quote_bry);} // ' key="'
}

View File

@@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*;
public class Bfr_arg__hatr_arg implements Bfr_arg_clearable {
private final byte[] atr_bgn;
private Bfr_arg_clearable val_as_arg;
public Bfr_arg__hatr_arg(byte[] key) {this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key);}
public Bfr_arg__hatr_arg Set_by_arg(Bfr_arg_clearable v) {val_as_arg = v; return this;}
public Bfr_arg__hatr_arg Set_by_arg_empty() {val_as_arg = Bfr_arg__html_atr__empty.Instance; return this;}
public void Bfr_arg__clear() {val_as_arg = null;}
public boolean Bfr_arg__missing() {return val_as_arg == null || val_as_arg.Bfr_arg__missing();}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
val_as_arg.Bfr_arg__add(bfr);
bfr.Add_byte_quote();
}
}
class Bfr_arg__html_atr__empty implements Bfr_arg_clearable {
public void Bfr_arg__clear() {}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {}
public static final Bfr_arg__html_atr__empty Instance = new Bfr_arg__html_atr__empty(); Bfr_arg__html_atr__empty() {}
}

View File

@@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.core.primitives.*;
public class Bfr_arg__hatr_bry implements Bfr_arg_clearable {
private final byte[] atr_bgn;
public Bfr_arg__hatr_bry(byte[] key) {this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key); this.Bfr_arg__clear();}
private Bfr_arg_clearable arg;
public byte[] Src() {return src;} private byte[] src;
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public Bfr_arg__hatr_bry Set_by_bry(byte[] bry) {src = bry; return this;}
public Bfr_arg__hatr_bry Set_by_mid(byte[] bry, int bgn, int end) {src = bry; src_bgn = bgn; src_end = end; return this;}
public Bfr_arg__hatr_bry Set_by_arg(Bfr_arg_clearable v) {arg = v; return this;}
public Bfr_arg__hatr_bry Set_by_mid_or_empty(byte[] bry, int bgn, int end) {
if (end == -1) this.Set_by_bry(Bry_.Empty);
else this.Set_by_mid(bry, bgn, end);
return this;
}
public Bfr_arg__hatr_bry Set_by_mid_or_null(byte[] bry, int bgn, int end) {
if (end != -1) this.Set_by_mid(bry, bgn, end);
return this;
}
public void Bfr_arg__clear() {arg = null; src = null; src_bgn = src_end = -1;}
public boolean Bfr_arg__missing() {return src == null && (arg == null || arg.Bfr_arg__missing());}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
if (src == null) arg.Bfr_arg__add(bfr);
else if (src_bgn == -1) bfr.Add(src);
else bfr.Add_mid(src, src_bgn, src_end);
bfr.Add_byte_quote();
}
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*;
public class Bfr_arg__hatr_cls implements Bfr_arg {
private final byte[] atr_bgn;
private byte[][] ary;
public Bfr_arg__hatr_cls() {this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(gplx.langs.htmls.Gfh_atr_.Bry__class);}
public Bfr_arg__hatr_cls Set_by_ary(byte[][] v) {ary = v; return this;}
public void Bfr_arg__clear() {ary = null;}
public boolean Bfr_arg__missing() {return ary == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
int len = ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte_space();
bfr.Add(ary[i]);
}
bfr.Add_byte_quote();
}
}

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.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
public class Bfr_arg__hatr_fmtr implements Bfr_arg {
private final byte[] atr_bgn;
private final Bry_fmtr fmtr = Bry_fmtr.new_();
private Object[] args;
public Bfr_arg__hatr_fmtr(byte[] key, String fmt, String... keys) {
this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key);
this.fmtr.Fmt_(fmt).Keys_(keys);
this.Clear();
}
public void Set_args(Object... args) {this.args = args;}
public void Clear() {args = null;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return args == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
fmtr.Bld_bfr_many(bfr, args);
bfr.Add_byte_quote();
}
}

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.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*;
public class Bfr_arg__hatr_id implements Bfr_arg_clearable {
private final byte[] atr_bgn;
private final byte[] bry; private int num;
public Bfr_arg__hatr_id(byte[] bry) {this.bry = bry; this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(gplx.langs.htmls.Gfh_atr_.Bry__id);}
public Bfr_arg__hatr_id Set(int num) {this.num = num; return this;}
public void Bfr_arg__clear() {num = -1;}
public boolean Bfr_arg__missing() {return num == -1;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
bfr.Add(bry);
bfr.Add_int_variable(num);
bfr.Add_byte_quote();
}
public static Bfr_arg__hatr_id New(String v) {return new Bfr_arg__hatr_id(Bry_.new_u8(v));}
public static Bfr_arg__hatr_id New(byte[] v) {return new Bfr_arg__hatr_id(v);}
}

View File

@@ -16,16 +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.bfr_args; 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 Bfr_arg__id extends gplx.core.brys.Bfr_arg_base {
private byte[] prefix; private int id;
public Bfr_arg__id Set(byte[] prefix, int id) {
this.prefix = prefix;
this.id = id;
return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add(prefix);
bfr.Add_int_variable(id);
import gplx.core.brys.*;
public class Bfr_arg__hatr_int implements Bfr_arg_clearable {
private final byte[] atr_bgn;
private int val;
public Bfr_arg__hatr_int(byte[] key) {this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key);}
public Bfr_arg__hatr_int Set_by_int(int v) {val = v; return this;}
public void Bfr_arg__clear() {val = Int_.Min_value;}
public boolean Bfr_arg__missing() {return val == Int_.Min_value;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
bfr.Add_int_variable(val);
bfr.Add_byte_quote();
}
}

View File

@@ -15,37 +15,38 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.nss.*;
public class Bfr_arg__href extends gplx.core.brys.Bfr_arg_base implements gplx.core.brys.Clear_able {
private byte[] val; private int val_bgn, val_end;
private int href_type;
public void Clear() {
href_type = Tid__null;
}
public void Set_by_atr(gplx.langs.htmls.parsers.Html_atr atr) {Set_by_mid(atr.Src(), atr.Val_bgn(), atr.Val_end());}
public void Set_by_mid(byte[] v, int bgn, int end) {this.val = v; this.href_type = Tid__mid; this.val_bgn = bgn; this.val_end = end;}
public void Set_by_raw(byte[] v) {this.val = v; this.href_type = Tid__raw;}
public void Set_by_page(byte[] v) {this.val = v; this.href_type = Tid__page;}
public void Set_by_file(byte[] v) {this.val = v; this.href_type = Tid__file;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
if (val == null) return;
switch (href_type) {
case Tid__raw:
bfr.Add(val);
break;
case Tid__mid:
bfr.Add_mid(val, val_bgn, val_end);
break;
case Tid__page:
bfr.Add(Xoh_href_.Bry__wiki); // '/wiki/'
bfr.Add(val); // 'File:A.png'
break;
case Tid__file:
bfr.Add(Xoh_href_.Bry__wiki).Add(Xow_ns_.Bry__file).Add_byte_colon();
bfr.Add(val);
break;
}
}
private static final int Tid__null = 0, Tid__raw = 1, Tid__page = 2, Tid__file = 3, Tid__mid = 4;
}
//namespace gplx.xowa.htmls.core.wkrs.bfr_args {
// using gplx.xowa.htmls.hrefs; using gplx.xowa.wikis.nss;
// public class Bfr_arg__href : gplx.core.brys.Bfr_arg_clearable {
// private byte[] val; private int val_bgn, val_end;
// private int href_type;
//// public void Clear() {
//// href_type = Tid__null;
//// }
// public void Set_by_atr(gplx.langs.htmls.docs.Gfh_atr atr) {Set_by_mid(atr.Src(), atr.Val_bgn(), atr.Val_end());}
// public void Set_by_mid(byte[] v, int bgn, int end) {this.val = v; this.href_type = Tid__mid; this.val_bgn = bgn; this.val_end = end;}
// public void Set_by_raw(byte[] v) {this.val = v; this.href_type = Tid__raw;}
// public void Set_by_page(byte[] v) {this.val = v; this.href_type = Tid__page;}
// public void Set_by_file(byte[] v) {this.val = v; this.href_type = Tid__file;}
// public void Bfr_arg__add(Bry_bfr bfr) {
// if (val == null) return;
// switch (href_type) {
// case Tid__raw:
// bfr.Add(val);
// break;
// case Tid__mid:
// bfr.Add_mid(val, val_bgn, val_end);
// break;
// case Tid__page:
// bfr.Add(Xoh_href_.Bry__wiki); // '/wiki/'
// bfr.Add(val); // 'File:A.png'
// break;
// case Tid__file:
// bfr.Add(Xoh_href_.Bry__wiki).Add(Xow_ns_.Bry__file).Add_byte_colon();
// bfr.Add(val);
// break;
// }
// }
// private static final int Tid__null = 0, Tid__raw = 1, Tid__page = 2, Tid__file = 3, Tid__mid = 4;
// }
//}

View File

@@ -1,76 +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.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*;
public class Bfr_arg__html_atr implements Bfr_arg, Clear_able {
private final byte[] atr_bgn;
private int val_type;
private int val_as_int;
private byte[] val_as_bry; private int val_as_bry_bgn, val_as_bry_end;
private byte[][] val_as_ary;
private Bfr_arg val_as_arg;
public Bfr_arg__html_atr(byte[] key) {this.atr_bgn = Bld_atr_bgn(key);}
public void Clear() {
val_type = Tid__null;
val_as_arg = null;
val_as_int = Int_.Min_value;
val_as_bry = null;
val_as_ary = null;
}
public byte[] Val_as_bry() {return val_as_bry;}
public int Val_as_bry_bgn() {return val_as_bry_bgn;}
public int Val_as_bry_end() {return val_as_bry_end;}
public Bfr_arg__html_atr Set_by_arg(Bfr_arg v) {val_type = Tid__arg; val_as_arg = v; return this;}
public Bfr_arg__html_atr Set_by_int(int v) {val_type = Tid__int; val_as_int = v; return this;}
public Bfr_arg__html_atr Set_by_ary(byte[]... ary) {val_type = Tid__bry__ary; val_as_ary = ary; return this;}
public Bfr_arg__html_atr Set_by_bry(byte[] bry) {val_type = Tid__bry__val; val_as_bry = bry; return this;}
public Bfr_arg__html_atr Set_by_mid(byte[] bry, int bgn, int end) {val_type = Tid__bry__mid; val_as_bry = bry; val_as_bry_bgn = bgn; val_as_bry_end = end; return this;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__exists() {
switch (val_type) {
case Tid__null: return false;
case Tid__arg: return val_as_arg.Bfr_arg__exists();
case Tid__int: return val_as_int != Int_.Min_value;
case Tid__bry__ary: return val_as_ary != null;
case Tid__bry__val: return val_as_bry != null;
case Tid__bry__mid: return val_as_bry != null;
default: throw Err_.new_unhandled(val_type);
}
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (!Bfr_arg__exists()) return;
bfr.Add(atr_bgn);
switch (val_type) {
case Tid__arg: val_as_arg.Bfr_arg__add(bfr); break;
case Tid__int: bfr.Add_int_variable(val_as_int); break;
case Tid__bry__val: bfr.Add(val_as_bry); break;
case Tid__bry__mid: bfr.Add_mid(val_as_bry, val_as_bry_bgn, val_as_bry_end); break;
case Tid__bry__ary:
int len = val_as_ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte_space();
byte[] v = val_as_ary[i];
bfr.Add(v);
}
break;
}
bfr.Add_byte_quote();
}
public static byte[] Bld_atr_bgn(byte[] key) {return Bry_.Add(Byte_ascii.Space_bry, key, Byte_ascii.Eq_bry, Byte_ascii.Quote_bry);} // ' key="'
private static final int Tid__null = 0, Tid__arg = 1, Tid__int = 2, Tid__bry__mid = 3, Tid__bry__val = 4, Tid__bry__ary = 5;
}

View File

@@ -24,9 +24,9 @@ public class Bfr_arg__wrapper implements Bfr_arg {
}
public Bfr_arg__wrapper Set(Bfr_arg v) {inner = v; return this;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__exists() {return inner != Bfr_arg_.Noop;}
public boolean Bfr_arg__missing() {return inner == Bfr_arg_.Noop;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (!Bfr_arg__exists()) return;
if (Bfr_arg__missing()) return;
inner.Bfr_arg__add(bfr);
}
}

View File

@@ -16,15 +16,15 @@ 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.langs.htmls.*; import gplx.langs.htmls.docs.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_escape_data implements Html_doc_wkr {
private final Xoh_hdoc_wkr wkr;
public Xoh_escape_data(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
public byte[] Hook() {return Xoh_hzip_dict_.Escape_bry;}
public class Xoh_escape_data implements Gfh_doc_wkr {
private final Xoh_hdoc_wkr wkr;
public Xoh_escape_data(Xoh_hdoc_wkr wkr, byte hook_byte) {this.wkr = wkr; this.hook = Bry_.New_by_byte(hook_byte);}
public byte[] Hook() {return hook;} private final byte[] hook; // NOTE: bry with 1 member which is hook to be escaped; EX: "1" or "2" or "27"
public int Parse(byte[] src, int src_bgn, int src_end, int pos) {
int rv = pos + 1;
wkr.On_escape(pos, rv);
wkr.On_escape(this);
return rv;
}
}

View File

@@ -20,16 +20,18 @@ import gplx.core.brys.*; import gplx.core.threads.poolables.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_escape_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
private byte escape_byte;
public int Tid() {return Xoh_hzip_dict_.Tid__escape;}
public byte[] Hook() {return hook;} private byte[] hook;
public String Key() {return Xoh_hzip_dict_.Key__escape;}
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
bfr.Add(hook);
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_escape_data data = (Xoh_escape_data)data_obj;
bfr.Add(hook); // EX: 1,0
bfr.Add(data.Hook()); // EX: 2
hctx.Hzip__stat().Escape_add(escape_byte);
return this;
}
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
bfr.Add_byte(Xoh_hzip_dict_.Escape);
return rdr.Pos();
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
bfr.Add_byte(rdr.Read_byte());
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {

View File

@@ -19,7 +19,13 @@ package gplx.xowa.htmls.core.wkrs.escapes; import gplx.*; import gplx.xowa.*; im
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
public class Xoh_escape_hzip_tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
@Test public void Basic() {
fxt.Test__bicode("~u", "");
@Test public void Escape() {
fxt.Test__bicode("!" , String_.new_a7(Bry_.New_by_byte(Xoh_pool_mgr__hzip.Hook__core)));
}
@Test public void Html() {
fxt.Test__bicode("!" , String_.new_a7(Bry_.New_by_byte(Xoh_pool_mgr__hzip.Hook__html)));
}
@Test public void Mw() {
fxt.Test__bicode("!", "");
}
}

View File

@@ -0,0 +1,125 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.langs.htmls.styles.*; import gplx.langs.htmls.clses.*;
import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.xtns.gallery.*;
public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { //
private final List_adp itms_list = List_adp_.new_();
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public int Gly_tid() {return gly_tid;} private int gly_tid;
public int Gly_w() {return gly_w;} private int gly_w;
public int Xtra_atr_bgn() {return xtra_atr_bgn;} private int xtra_atr_bgn;
public int Xtra_atr_end() {return xtra_atr_end;} private int xtra_atr_end;
public boolean Xtra_atr_exists() {return xtra_atr_end > xtra_atr_bgn;}
public int Xtra_cls_bgn() {return xtra_cls_bgn;} private int xtra_cls_bgn;
public int Xtra_cls_end() {return xtra_cls_end;} private int xtra_cls_end;
public boolean Xtra_cls_exists() {return xtra_cls_end > xtra_cls_bgn;}
public int Xtra_style_bgn() {return xtra_style_bgn;} private int xtra_style_bgn;
public int Xtra_style_end() {return xtra_style_end;} private int xtra_style_end;
public boolean Xtra_style_exists() {return xtra_style_end > xtra_style_bgn;}
public int Itms__len() {return itms_list.Count();}
public Xoh_gly_itm_data Itms__get_at(int i) {return (Xoh_gly_itm_data)itms_list.Get_at(i);}
private void Clear() {
this.gly_tid = Byte_.Max_value_127;
this.gly_w = 0;
this.xtra_atr_bgn = xtra_atr_end = xtra_cls_bgn = xtra_cls_end = xtra_style_bgn = xtra_style_end = -1;
itms_list.Clear();
}
public boolean Parse1(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
this.Clear();
this.src_bgn = ul_head.Src_bgn();
if (!Parse_cls (src, tag_rdr, ul_head)) return false;
if (!Parse_style(src, tag_rdr, ul_head)) return false;
Parse_ul_atrs(src, tag_rdr, ul_head);
Gfh_tag li_head = null;
while (true) {
li_head = tag_rdr.Tag__peek_fwd_head();
if (li_head.Name_id() != Gfh_tag_.Id__li) break; // no more <li>; break;
if (!li_head.Atrs__cls_has(Atr__cls__gallerybox)) return false;
tag_rdr.Pos_(li_head.Src_end());
Xoh_gly_itm_data itm_parser = new Xoh_gly_itm_data();
if (!itm_parser.Parse1(hdoc_wkr, hctx, src, tag_rdr, li_head)) return false;
tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__li);
itms_list.Add(itm_parser);
}
Gfh_tag ul_tail = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__ul);
this.src_end = ul_tail.Src_end();
hdoc_wkr.On_gly(this);
return true;
}
private boolean Parse_cls(byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
Gfh_atr ul_cls = ul_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__class);
Gfh_class_parser_.Parse(src, ul_cls.Val_bgn(), ul_cls.Val_end(), this);
if (gly_tid == Byte_.Max_value_127) {
tag_rdr.Err_wkr().Fail("unable to find gallery tid");
return false;
}
return true;
}
private boolean Parse_style(byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
Gfh_atr ul_style = ul_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__style);
Gfh_style_parser_.Parse(src, ul_style.Val_bgn(), ul_style.Val_end(), this); // parse for width; note width only appears if items_per_row is specified
return true;
}
private void Parse_ul_atrs(byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
int atrs_len = ul_head.Atrs__len();
for (int i = 0; i < atrs_len; ++i) {
Gfh_atr hatr = ul_head.Atrs__get_at(i);
if (Bry_.Eq(hatr.Key(), Gfh_atr_.Bry__class)) {}
else if (Bry_.Eq(hatr.Key(), Gfh_atr_.Bry__style)) {}
else {
if (xtra_atr_bgn == -1) this.xtra_atr_bgn = hatr.Atr_bgn();
this.xtra_atr_end = hatr.Atr_end();
}
}
}
public boolean On_cls(byte[] src, int atr_idx, int atr_bgn, int atr_end, int val_bgn, int val_end) {
if (Bry_.Match(src, val_bgn, val_end, Atr__cls__gallery)) {} // ignore "gallery"
else if (Bry_.Match(src, val_bgn, val_bgn + Atr__cls__mw_gallery.length, Atr__cls__mw_gallery)) { // starts with 'mw-gallery-'
int tid_bgn = val_bgn + Atr__cls__mw_gallery.length;
this.gly_tid = Gallery_mgr_base_.Hash.Get_as_byte_or(src, tid_bgn, val_end, Byte_.Max_value_127);
return true;
}
else {
if (this.xtra_cls_bgn == -1) {
this.xtra_cls_bgn = val_bgn;
this.xtra_cls_end = atr_end;
}
}
return true;
}
public boolean On_atr(byte[] src, int atr_idx, int atr_bgn, int atr_end, int key_bgn, int key_end, int val_bgn, int val_end) {
if (Bry_.Match(src, key_bgn, key_end, Style__max_width)) // 'max-width'
gly_w = Bry_.To_int_or__lax(src, val_bgn, val_end, 0);
else if (Bry_.Match(src, key_bgn, key_end, Style___width)) {} // '_width'
else {
if (this.xtra_style_bgn == -1) {
this.xtra_style_bgn = key_bgn;
this.xtra_style_end = atr_end;
}
}
return true;
}
public static final byte[] Atr__cls__gallery = Bry_.new_a7("gallery");
private static final byte[] Atr__cls__mw_gallery = Bry_.new_a7("mw-gallery-"), Atr__cls__gallerybox = Bry_.new_a7("gallerybox")
, Style__max_width = Bry_.new_a7("max-width"), Style___width = Bry_.new_a7("_width")
;
}

View File

@@ -1,49 +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.glys; 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.langs.htmls.parsers.styles.*; import gplx.langs.htmls.parsers.clses.*;
public class Xoh_gly_grp_parser implements Html_atr_class_wkr {
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
public int Rng_end() {return rng_end;} private int rng_end;
// private Xoh_gly_itm_parser itm_parser = new Xoh_gly_itm_parser();
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag ul_tag) {
this.rng_bgn = ul_tag.Src_bgn();
/*
parse class for traditional
parse style for max_width
*/
// Html_tag cur_tag = null;
// while (true) {
// cur_tag = tag_rdr.Tag__move_fwd_head();
// if (cur_tag.Name_id() != Html_tag_.Id__li) break; // no more <li>; break;
// itm_parser.Parse(hdoc_wkr, hctx, src, tag_rdr, cur_tag);
// }
// hdoc_wkr.On_thm(this);
Html_tag cur_tag = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__ul);
this.rng_end = cur_tag.Src_end();
return rng_end;
}
public boolean On_cls(byte[] src, int atr_idx, int atr_bgn, int atr_end, int val_bgn, int val_end) {
// if (Bry_.Match(src, val_bgn, val_end, Bry__cls__traditional)) {
//
// }
return false;
}
public static final byte[] Atr__class__gallery = Bry_.new_a7("gallery");
}

View File

@@ -0,0 +1,106 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*;
class Xoh_gly_grp_wtr implements Bfr_arg {
private final Bfr_arg_clearable[] arg_ary;
private final Bfr_arg__hatr_id ul_id = Bfr_arg__hatr_id.New("xogly_li_");
private final Bfr_arg__hatr_gly_style ul_style = new Bfr_arg__hatr_gly_style(Gfh_atr_.Bry__style);
private byte[] ul_cls, xtra_cls, xtra_atr_bry, ul_nl;
private final Xoh_gly_itm_list_wtr itm_list_wtr = new Xoh_gly_itm_list_wtr();
public Xoh_gly_grp_wtr() {
arg_ary = new Bfr_arg_clearable[] {ul_id};
}
public void Init(boolean mode_is_diff, int id, byte[] cls, int ul_w, byte[] xtra_cls, byte[] xtra_style_bry, byte[] xtra_atr_bry, Xoh_gly_itm_wtr[] ary) {
this.Clear();
if (!mode_is_diff)
ul_id.Set(id);
this.ul_cls = cls;
this.xtra_cls = xtra_cls == null ? Bry_.Empty : Bry_.Add(Byte_ascii.Space_bry, xtra_cls);
this.xtra_atr_bry = xtra_atr_bry;
this.ul_nl = ary.length == 0 ? Bry_.Empty : Byte_ascii.Nl_bry; // TIDY: <ul></ul> should be on same line if 0 items
itm_list_wtr.Init(ary);
ul_style.Set_args(ul_w, xtra_style_bry);
}
public void Clear() {
for (Bfr_arg_clearable arg : arg_ary)
arg.Bfr_arg__clear();
ul_id.Bfr_arg__clear();
ul_style.Clear();
ul_cls = null;
}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, ul_id, ul_cls, xtra_cls, ul_style, xtra_atr_bry, itm_list_wtr, ul_nl);
}
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<ul~{id} class=\"gallery mw-gallery-~{cls}~{xtra_cls}\"~{style}~{xtra_atr}>~{itms}~{ul_nl}</ul>"
), "id", "cls", "xtra_cls", "style", "xtra_atr", "itms", "ul_nl");
}
class Xoh_gly_itm_list_wtr implements Bfr_arg {
private Xoh_gly_itm_wtr[] ary; private int ary_len;
public void Init(Xoh_gly_itm_wtr[] ary) {
this.ary = ary; this.ary_len = ary.length;
for (int i = 0; i < ary_len; ++i)
ary[i].Clear();
}
public void Bfr_arg__clear() {ary = null;}
public boolean Bfr_arg__missing() {return ary == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
for (int i = 0; i < ary_len; ++i) {
Xoh_gly_itm_wtr itm = ary[i];
itm.Bfr_arg__add(bfr);
}
}
}
class Bfr_arg__hatr_gly_style implements Bfr_arg {
private final byte[] atr_bgn;
private int width;
private byte[] xtra_cls;
public Bfr_arg__hatr_gly_style(byte[] key) {
this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key);
this.Clear();
}
public void Set_args(int w, byte[] xtra_cls) {this.width = w; this.xtra_cls = xtra_cls;}
public void Clear() {width = 0; xtra_cls = null;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return width == 0 && xtra_cls == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
if (width > 0) {
bfr.Add(Style__frag_1);
bfr.Add_int_variable(width);
bfr.Add(Style__frag_2);
bfr.Add_int_variable(width);
bfr.Add(Style__frag_3);
}
if (xtra_cls != null) {
if (width > 0) bfr.Add_byte_space();
bfr.Add(xtra_cls);
}
bfr.Add_byte_quote();
}
private static final byte[]
Style__frag_1 = Bry_.new_a7("max-width:")
, Style__frag_2 = Bry_.new_a7("px; _width:")
, Style__frag_3 = Bry_.new_a7("px;")
;
}

View File

@@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
public class Xoh_gly_html__dump__tst {
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.Test__html(String_.Concat_lines_nl_skip_last
( "<gallery>"
, "File:A.jpg|A1"
, "File:B.jpg|B1"
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
, " <li class='gallerybox' style='width:155px;'>"
, " <div style='width:155px;'>"
, " <div class='thumb' style='width:150px;'>"
, " <div style='margin:15px auto;'>"
, " <a href='/wiki/File:A.jpg' class='image' xowa_title='A.jpg'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''/></a>"
, " </div>"
, " </div>"
, " <div class='gallerytext'><p>A1"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, " <li class='gallerybox' style='width:155px;'>"
, " <div style='width:155px;'>"
, " <div class='thumb' style='width:150px;'>"
, " <div style='margin:15px auto;'>"
, " <a href='/wiki/File:B.jpg' class='image' xowa_title='B.jpg'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''/></a>"
, " </div>"
, " </div>"
, " <div class='gallerytext'><p>B1"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"));
}
}

View File

@@ -17,21 +17,84 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.threads.poolables.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
import gplx.xowa.xtns.gallery.*;
public class Xoh_gly_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
private final Xoh_gly_grp_wtr grp_wtr = new Xoh_gly_grp_wtr();
public int Tid() {return Xoh_hzip_dict_.Tid__gly;}
public String Key() {return Xoh_hzip_dict_.Key__gly;}
public byte[] Hook() {return hook;} private byte[] hook;
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_gly_grp_parser data = (Xoh_gly_grp_parser)data_obj;
bfr.Add_mid(src, data.Rng_bgn(), data.Rng_end());
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_gly_grp_data data = (Xoh_gly_grp_data)data_obj;
boolean xtra_atr = flag_bldr.Set_as_bool(Flag__ul__xtra_atr , data.Xtra_atr_exists());
boolean xtra_cls = flag_bldr.Set_as_bool(Flag__ul__xtra_cls , data.Xtra_cls_exists());
boolean xtra_style = flag_bldr.Set_as_bool(Flag__ul__xtra_style , data.Xtra_style_exists());
flag_bldr.Set(Flag__gly_tid, data.Gly_tid());
int itms_len = data.Itms__len();
bfr.Add(hook);
Xoh_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
Xoh_hzip_int_.Encode(1, bfr, data.Gly_w());
if (xtra_cls) bfr.Add_hzip_mid(src, data.Xtra_cls_bgn(), data.Xtra_cls_end());
if (xtra_style) bfr.Add_hzip_mid(src, data.Xtra_style_bgn(), data.Xtra_style_end());
if (xtra_atr) bfr.Add_hzip_mid(src, data.Xtra_atr_bgn(), data.Xtra_atr_end());
Xoh_hzip_int_.Encode(1, bfr, itms_len);
for (int i = 0; i < itms_len; ++i) {
Xoh_gly_itm_data itm_parser = data.Itms__get_at(i);
bfr.Add_hzip_int(1, itm_parser.Li_w());
bfr.Add_hzip_int(1, itm_parser.Div_1_w());
bfr.Add_hzip_int(1, itm_parser.Div_2_margin());
bfr.Add_byte((byte)(itm_parser.Capt_tid() + gplx.core.encoders.Base85_.A7_offset));
bfr.Add_hzip_mid(src, itm_parser.Capt_bgn(), itm_parser.Capt_end());
Xoh_hzip_wkr hzip_wkr = hctx.Pool_mgr__hzip().Mw__img();
hzip_wkr.Encode1(bfr, hdoc_wkr, hctx, hpg, false, src, itm_parser.Img_parser());
hzip_wkr.Pool__rls();
}
return this;
}
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
return src_bgn + 2;
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
int flag = rdr.Read_hzip_int(1); flag_bldr.Decode(flag);
boolean xtra_atr = flag_bldr.Get_as_bool(Flag__ul__xtra_atr);
boolean xtra_cls = flag_bldr.Get_as_bool(Flag__ul__xtra_cls);
boolean xtra_style = flag_bldr.Get_as_bool(Flag__ul__xtra_style);
byte cls_tid = flag_bldr.Get_as_byte(Flag__gly_tid);
byte[] cls_bry = Gallery_mgr_base_.Get_bry_by_tid(cls_tid);
int ul_w = rdr.Read_hzip_int(1);
byte[] xtra_cls_bry = xtra_cls ? rdr.Read_bry_to(): null;
byte[] xtra_style_bry = xtra_style ? rdr.Read_bry_to(): null;
byte[] xtra_atr_bry = xtra_atr ? rdr.Read_bry_to(): null;
int li_len = rdr.Read_hzip_int(1);
int uid = hctx.Uid__gly__nxt();
Xoh_gly_itm_wtr[] itm_ary = new Xoh_gly_itm_wtr[li_len];
for (int i = 0; i < li_len; ++i) {
Xoh_gly_itm_wtr itm_wtr = new Xoh_gly_itm_wtr();
itm_ary[i] = itm_wtr;
int li_w = rdr.Read_hzip_int(1);
int div_1_w = rdr.Read_hzip_int(1);
int div_2_margin = rdr.Read_hzip_int(1);
byte capt_tid = (byte)(rdr.Read_byte() - gplx.core.encoders.Base85_.A7_offset);
byte[] capt_bry = rdr.Read_bry_to();
Xoh_data_itm img_data = hctx.Pool_mgr__data().Get_by_tid(Xoh_hzip_dict_.Tid__img);
Xoh_hzip_wkr img_hzip = hctx.Pool_mgr__hzip().Mw__img();
img_hzip.Decode1(bfr, hdoc_wkr, hctx, hpg, rdr, src, src_bgn, src_end, img_data);
itm_wtr.Init(true, uid, li_w, div_1_w, div_2_margin, capt_tid, capt_bry);
itm_wtr.Img_wtr().Init_by_decode(hpg, hctx, src, img_data);
img_data.Pool__rls();
img_hzip.Pool__rls();
}
grp_wtr.Init(hctx.Mode_is_diff(), uid, cls_bry, ul_w, xtra_cls_bry, xtra_style_bry, xtra_atr_bry, itm_ary);
grp_wtr.Bfr_arg__add(bfr);
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_gly_hzip rv = new Xoh_gly_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(1, 1, 1, 3);
private static final int // SERIALIZED
Flag__ul__xtra_atr = 0
, Flag__ul__xtra_cls = 1
, Flag__ul__xtra_style = 2
, Flag__gly_tid = 3
;
}

View File

@@ -18,40 +18,161 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
public class Xoh_gly_hzip_tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
private String Html__basic = gplx.langs.htmls.Html_utl.Replace_apos(String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px;_width:978px;'>"
, " <li class='gallerybox' style='width: 155px'>"
, " <div style='width: 155px'>"
, " <div class='thumb' style='width: 150px;'>"
, " <div style='margin:75px auto;'>"
, " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a>"
, " </div>"
, " </div>"
, " <div class='gallerytext'>"
, " <p>"
, " abc"
, " </p>"
, " </div>"
, " </div>"
, " </li>"
, " <li class='gallerybox' style='width: 155px'>"
, " <div style='width: 155px'>"
, " <div class='thumb' style='width: 150px;'>"
, " <div style='margin:75px auto;'>"
, " <a href='/wiki/File:B.png' class='image' xowa_title='B.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a>"
, " </div>"
, " </div>"
, " <div class='gallerytext'>"
, " <p>"
, " abc"
, " </p>"
, " </div>"
, " </div>"
, " </li>"
, "</ul>"
));
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Test public void Basic() {
fxt.Test__bicode(Html__basic, Html__basic);
fxt.Test__bicode("~'!{,L#{\"g{\"b0!A1~!1A.png~9\"D\"D{\"g{\"b0!B1~!1B.png~9\"D\"Dabc", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:B.png' class='image' xowa_title='B.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>B1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>abc"));
}
@Test public void Capt_is_empty() { // PURPOSE: handle empty caption
fxt.Test__bicode("~'!!#{\"g{\"b0#~!1A.png~9\"D\"D{\"g{\"b0#!1A.png9\"D\"D<p>abc</p>", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'></div>"
, "</div>"
, "</li>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'></div>"
, "</div>"
, "</li>"
, "</ul><p>abc</p>"));
}
@Test public void Capt_is_br() { // PURPOSE: handle captions which have <br>, not <p>; PAGE:s.w:Sociology; DATE:2015-12-20
fxt.Test__bicode("~'!!\"{\"g{\"b0\"<b><i>A1</i></b>~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'><br>"
, "<b><i>A1</i></b>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void No_max_width() { // PURPOSE: if no perrow=# then no "style='max-width:###; _width:###;'"
fxt.Test__bicode("~'!!\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void Extra_cls() { // PURPOSE: handle extra cls; EX: <gallery class='abc'>
fxt.Test__bicode("~'1!cls1 cls2~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional cls1 cls2'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void Xtra_style__append() { // PURPOSE: handle appended style; EX: <gallery perrow=4 style='color:blue; float:left;'>
fxt.Test__bicode("~'){,Lcolor:blue; float:left;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue; float:left;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void Xtra_style__replace() { // PURPOSE: handle replaced style; EX: <gallery style='color:blue; float:left;'>
fxt.Test__bicode("~')!color:blue; float:left;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='color:blue; float:left;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void Xtra_atr() { // PURPOSE: handle extra atr; EX: <gallery id='abc'>
fxt.Test__bicode("~'A! id=\"abc\"\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' id='abc'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void Tidy__br_at_end() { // PURPOSE: handle inconsistent tidy behavior where <p> is put on one line ("<p>a</p>") unless it ends with <br> ("<p>a<br>\n</p>")
fxt.Test__bicode("~'!!\"{\"g{\"b0!A1<br>~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1<br>" // TIDY: <br> forces </p> to be on next line
, "</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void Tidy__empty() { // PURPOSE: no items should place </ul> on same line
fxt.Test__bicode("~'!!!", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'></ul>")); // TIDY: <ul></ul> should be on same line if 0 items
}
}

View File

@@ -0,0 +1,106 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.core.btries.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.langs.htmls.styles.*;
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*;
public class Xoh_gly_itm_data {
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public Xoh_img_data Img_parser() {return img_parser;} private Xoh_img_data img_parser = new Xoh_img_data();
public boolean Img_exists() {return img_exists;} private boolean img_exists;
public int Li_w() {return li_w;} private int li_w;
public int Div_1_w() {return div_1_w;} private int div_1_w;
public int Div_2_margin() {return div_2_margin;} private int div_2_margin;
public byte Capt_tid() {return capt_tid;} private byte capt_tid;
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
public int Capt_end() {return capt_end;} private int capt_end;
private void Clear() {
img_exists = false;
capt_bgn = capt_end = li_w = div_1_w = div_2_margin = -1;
capt_tid = Capt_tid__null;
}
public boolean Parse1(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag li_tag) {
this.Clear();
this.src_bgn = li_tag.Src_bgn();
this.li_w = li_tag.Atrs__style_get_as_int(Gfh_style_key_.Bry__width);
Gfh_tag div_0_head = tag_rdr.Tag__move_fwd_head();
if (!div_0_head.Chk_name(Gfh_tag_.Id__div)) return false; // <div style="width: 175px">
Gfh_tag div_1_head = tag_rdr.Tag__move_fwd_head();
if (!div_1_head.Chk(Gfh_tag_.Id__div, Xoh_thm_data.Atr__class__thumb)) return false; // chk for <div class="thumb" style="height: 170px;">
this.div_1_w = div_1_head.Atrs__style_get_as_int(Gfh_style_key_.Bry__width);
int div_2_bgn = div_1_head.Src_end();
Gfh_tag div_1_tail = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__div); // </div> for class="thumb"
int div_2_end = div_1_tail.Src_bgn();
Gfh_tag div_2_head = tag_rdr.Tag__find_fwd_head(div_2_bgn, div_2_end, Gfh_tag_.Id__div); // find <div style="margin:15px auto;">
if (div_2_head.Src_exists()) { // img_exists
img_exists = true;
this.div_2_margin = div_2_head.Atrs__style_get_as_int(Gfh_style_key_.Bry__margin);
tag_rdr.Pos_(div_2_head.Src_end());
Gfh_tag anch_tag = tag_rdr.Tag__move_fwd_head();
if (!anch_tag.Chk(Gfh_tag_.Id__a, Xoh_img_data.Bry__cls__anch__image)) return false;
if (!img_parser.Init_by_parse(hdoc_wkr, hctx, tag_rdr, src, anch_tag, null)) return false;
}
else {
img_exists = false;
}
if (!Parse_gallerytext(src, tag_rdr)) return false;
tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__div);
this.src_end = tag_rdr.Pos();
return true;
}
private boolean Parse_gallerytext(byte[] src, Gfh_tag_rdr tag_rdr) {
Gfh_tag capt_head = tag_rdr.Tag__move_fwd_head();
if (!capt_head.Chk(Gfh_tag_.Id__div, Atr__cls__gallerytext)) return false; // chk for <div class='gallerytext'>
int capt_head_end = capt_head.Src_end();
Gfh_tag capt_tail = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__div);
int capt_tail_bgn = capt_tail.Src_bgn();
int capt_tail_end = capt_tail.Src_end();
capt_bgn = Bry_find_.Find_fwd_while_not_ws(src, capt_head_end, capt_tail_bgn); // skip any \n, \s
if (capt_tail_bgn - capt_bgn == 0) {
capt_tid = Capt_tid__empty;
capt_end = capt_bgn;
return true; // EX: <div class='gallerytext'></div>
}
Object capt_tid_obj = Capt_tid__trie.Match_bgn(src, capt_bgn, capt_tail_bgn);
if (capt_tid_obj == null) return false; // something wrong;
this.capt_tid = ((Byte_obj_val)capt_tid_obj).Val();
boolean capt_head_is_p = false;
switch (capt_tid) {
case Capt_tid__p: capt_bgn += 3; capt_head_is_p = true; break; // EX: <div class='gallerytext'><p>
case Capt_tid__br: capt_bgn += 4; break; // EX: <div class='gallerytext'><br>
}
if (capt_head_is_p)
tag_rdr.Pos_(capt_bgn);
capt_bgn = Bry_find_.Find_fwd_while_not_ws(src, capt_bgn, capt_tail_bgn);
capt_end = capt_tail_bgn;
if (capt_head_is_p) {
Gfh_tag para_tail = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__p);
capt_end = para_tail.Src_bgn();
}
capt_end = Bry_find_.Find_bwd__skip_ws(src, capt_end, -1);
tag_rdr.Pos_(capt_tail_end);
return true;
}
private static final byte[] Atr__cls__gallerytext = Bry_.new_a7("gallerytext");
public static final byte Capt_tid__p = 0, Capt_tid__br = 1, Capt_tid__empty = 2, Capt_tid__null = 3;
private static final Btrie_slim_mgr Capt_tid__trie = Btrie_slim_mgr.ci_a7()
.Add_bry_byte(Gfh_tag_.P_lhs , Capt_tid__p)
.Add_bry_byte(Gfh_tag_.Br_lhs , Capt_tid__br)
;
}

View File

@@ -1,56 +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.glys; 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.langs.htmls.parsers.styles.*;
public class Xoh_gly_itm_parser {
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
public int Rng_end() {return rng_end;} private int rng_end;
// xoimg_parser
public boolean Img_exists() {return img_exists;} private boolean img_exists;
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
public int Capt_end() {return capt_end;} private int capt_end;
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag li_tag) {
this.rng_bgn = li_tag.Src_bgn();
this.rng_end = li_tag.Src_end();
tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__div); // <div style="width: 175px">
Html_tag div_1_head = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__div); // <div class="thumb" style="height: 170px;">
int file_text_bgn = div_1_head.Src_end();
Html_tag div_1_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
int file_text_end = div_1_tail.Src_bgn();
Html_tag img_tag = tag_rdr.Tag__find_fwd_head(file_text_bgn, file_text_end, Html_tag_.Id__div); // search <div style="margin:15px auto;">
if (img_tag.Src_exists()) { // img_exists
img_exists = true;
// div_nxt.Atrs__cls_has(Bry__gallery_text); // assert cls = Bry_gallery_text
}
else {
img_exists = false;
}
tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__div); // <div class="gallerytext">
Html_tag para_head = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__p);
capt_bgn = para_head.Src_end();
Html_tag para_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__p);
capt_end = para_tail.Src_bgn();
tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
this.rng_end = tag_rdr.Pos();
return rng_end;
}
// private static final byte[] Bry__gallery_text = Bry_.new_a7("gallerytext");
}

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.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
public class Xoh_gly_itm_wtr implements Bfr_arg {
private final Bfr_arg_clearable[] arg_ary;
private final Bfr_arg__hatr_id li_id = Bfr_arg__hatr_id.New("xogly_li_"), img_id = Bfr_arg__hatr_id.New(gplx.xowa.htmls.Xoh_img_mgr.Bry__html_uid)
, div_1_id = Bfr_arg__hatr_id.New("xogly_div1_"), div_2_id = Bfr_arg__hatr_id.New("xogly_div2_"), div_3_id = Bfr_arg__hatr_id.New("xogly_div3_");
private final Bfr_arg__itm_caption itm_caption_fmtr = new Bfr_arg__itm_caption();
private int li_w, div_1_w, div_2_margin;
public Xoh_gly_itm_wtr() {
arg_ary = new Bfr_arg_clearable[] {li_id, div_1_id, div_2_id, div_3_id, img_id};
}
public Xoh_img_wtr Img_wtr() {return img_wtr;} private final Xoh_img_wtr img_wtr = new Xoh_img_wtr();
public void Init(boolean mode_is_diff, int img_id, int li_w, int div_1_w, int div_2_margin, byte capt_tid, byte[] itm_caption) {
this.Clear();
this.li_w = li_w; this.div_1_w = div_1_w; this.div_2_margin = div_2_margin;
itm_caption_fmtr.Set(capt_tid, itm_caption);
if (!mode_is_diff) {
li_id.Set(img_id); div_1_id.Set(img_id); div_2_id.Set(img_id); div_3_id.Set(img_id); img_wtr.Img_id_(img_id);
}
img_wtr.Anch_cls_(Xoh_img_data.Bry__cls__anch__image);
}
public Xoh_gly_itm_wtr Clear() {
for (Bfr_arg_clearable arg : arg_ary)
arg.Bfr_arg__clear();
// img_wtr.Clear(); // TOMBSTONE: do not clear; clear will be called by Xoh_hzip_img.Decode1
return this;
}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, li_id, div_1_id, div_2_id, div_3_id, li_w, div_1_w, div_2_margin, img_wtr, itm_caption_fmtr);
}
public static final Xoh_gly_itm_wtr[] Ary_empty = new Xoh_gly_itm_wtr[0];
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, "<li~{li_id} class=\"gallerybox\" style=\"width:~{li_w}px;\">"
, "<div~{div_1_id} style=\"width:~{li_w}px;\">"
, "<div~{div_2_id} class=\"thumb\" style=\"width:~{div_1_w}px;\">"
, "<div~{div_3_id} style=\"margin:~{div_2_margin}px auto;\">~{img_itm}</div>"
, "</div>"
, "<div class=\"gallerytext\">~{itm_caption}</div>"
, "</div>"
, "</li>"
), "li_id", "div_1_id", "div_2_id", "div_3_id", "li_w", "div_1_w", "div_2_margin", "img_itm", "itm_caption");
}
class Bfr_arg__itm_caption implements Bfr_arg {
private byte capt_tid;
private byte[] capt_bry;
public void Set(byte tid, byte[] bry) {this.capt_tid = tid; this.capt_bry = bry;}
public void Bfr_arg__clear() {capt_bry = null;}
public boolean Bfr_arg__missing() {return capt_bry == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
switch (capt_tid) {
case Xoh_gly_itm_data.Capt_tid__empty: return; // <div class='gallerytext'></div>
case Xoh_gly_itm_data.Capt_tid__p: bfr.Add_byte_nl().Add(Gfh_tag_.P_lhs); break; // <div class='gallerytext'><p>
case Xoh_gly_itm_data.Capt_tid__br: bfr.Add(Gfh_tag_.Br_lhs).Add_byte_nl(); break; // <div class='gallerytext'><br>
}
bfr.Add(capt_bry);
int itm_caption_len = capt_bry.length;
if (capt_tid == Xoh_gly_itm_data.Capt_tid__p) {
if (itm_caption_len > 3 && Bry_.Match(capt_bry, itm_caption_len - 4, Gfh_tag_.Br_lhs)) bfr.Add_byte_nl();
bfr.Add(Gfh_tag_.P_rhs);
}
bfr.Add_byte_nl();
}
}

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.htmls.core.hzips.*;
public class Xoh_gly_itm_wtr_tst {
private final Xoh_gly_itm_wtr_fxt fxt = new Xoh_gly_itm_wtr_fxt();
@Test public void Basic() {
fxt.Init__gly(0, 155, 150, 5, "caption");
fxt.Init__img("/wiki/File:A.png", "A.png", "0|120|120|-1|-1|-1");
fxt.Test__write(String_.Concat_lines_nl_skip_last
( ""
, "<li id='xogly_li_0' class='gallerybox' style='width:155px;'>"
, "<div id='xogly_div1_0' style='width:155px;'>"
, "<div id='xogly_div2_0' class='thumb' style='width:150px;'>"
, "<div id='xogly_div3_0' style='margin:5px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|120|120|-1|-1|-1' width='0' height='0'></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>caption</p>"
, "</div>"
, "</div>"
, "</li>"
));
}
}
class Xoh_gly_itm_wtr_fxt {
private final Xoh_gly_itm_wtr wtr = new Xoh_gly_itm_wtr();
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
public void Init__gly(int id, int itm_w, int file_div_w, int file_div_margin, String caption) {
wtr.Init(Bool_.N, id, itm_w, file_div_w, file_div_margin, Xoh_gly_itm_data.Capt_tid__p, Bry_.new_a7(caption));
}
public void Init__img(String href, String xowa_title, String xoimg) {
wtr.Img_wtr().Init_by_gly(gplx.core.brys.args.Bfr_arg__bry.New(Bry_.new_u8(href)), Bry_.new_u8(xowa_title), gplx.core.brys.args.Bfr_arg__bry.New(Bry_.new_u8(xoimg)));
}
public void Test__write(String expd) {
expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
wtr.Bfr_arg__add(tmp_bfr);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -16,8 +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.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 {
import gplx.core.threads.poolables.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_hdr_data implements Xoh_data_itm {
public int Tid() {return Xoh_hzip_dict_.Tid__hdr;}
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public int Hdr_level() {return hdr_level;} private int hdr_level;
@@ -28,28 +31,34 @@ public class Xoh_hdr_parser {
public int Capt_end() {return capt_end;} private int capt_end;
public int Capt_rhs_bgn() {return capt_rhs_bgn;} private int capt_rhs_bgn;
public int Capt_rhs_end() {return capt_rhs_end;} private int capt_rhs_end;
public boolean Capt_rhs_exists() {return capt_rhs_exists;} private boolean capt_rhs_exists;
public boolean Capt_rhs_exists() {return capt_rhs_end > capt_rhs_bgn;}
public void Clear() {
this.anch_bgn = anch_end = capt_bgn = capt_end = capt_rhs_bgn = capt_rhs_end -1;
this.anch_is_diff = capt_rhs_exists = false;
this.anch_bgn = anch_end = capt_bgn = capt_end = capt_rhs_bgn = capt_rhs_end = -1;
this.anch_is_diff = false;
}
public boolean Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Html_tag_rdr tag_rdr, byte[] src, Html_tag hdr_head, Html_tag span_head) {
public boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag hdr_head, Gfh_tag span_head) {
this.Clear();
this.src_bgn = hdr_head.Src_bgn(); this.hdr_level = hdr_head.Name_id();
Html_atr anch_atr = span_head.Atrs__get_by_or_fail(Html_atr_.Bry__id);
Gfh_atr anch_atr = span_head.Atrs__get_by_or_fail(Gfh_atr_.Bry__id);
this.anch_bgn = anch_atr.Val_bgn(); this.anch_end = anch_atr.Val_end();
this.capt_bgn = span_head.Src_end();
Html_tag hdr_tail = tag_rdr.Tag__move_fwd_tail(hdr_level); // find </h2> not </span_head> since <span_head> can be nested, but <h2> cannot
Html_tag span_tail = tag_rdr.Tag__peek_bwd_tail(Html_tag_.Id__span); // get </span_head> before </h2>
Gfh_tag hdr_tail = tag_rdr.Tag__move_fwd_tail(hdr_level); // find </h2> not </span_head> since <span_head> can be nested, but <h2> cannot
Gfh_tag span_tail = tag_rdr.Tag__peek_bwd_tail(Gfh_tag_.Id__span); // get </span_head> before </h2>
this.capt_end = span_tail.Src_bgn();
if (span_tail.Src_end() != hdr_tail.Src_bgn()) {
capt_rhs_exists = true;
capt_rhs_bgn = span_tail.Src_end(); capt_rhs_end = hdr_tail.Src_bgn();
}
this.anch_is_diff = !Bry_.Match_w_swap(src, capt_bgn, capt_end, src, anch_bgn, anch_end, Byte_ascii.Space, Byte_ascii.Underline); // anch is different than capt; occurs with html and dupe-anchors; EX: "==<i>A</i>==" -> id='A'
this.src_end = tag_rdr.Pos();
hdoc_wkr.On_hdr(this);
return true;
}
public void Init_by_decode(int hdr_level, boolean anch_is_diff, int anch_bgn, int anch_end, int capt_bgn, int capt_end, int capt_rhs_bgn, int capt_rhs_end) {
this.hdr_level = hdr_level;
this.anch_is_diff = anch_is_diff;
this.anch_bgn = anch_bgn; this.anch_end = anch_end; this.capt_bgn = capt_bgn; this.capt_end = capt_end;
this.capt_rhs_bgn = capt_rhs_bgn; this.capt_rhs_end = capt_rhs_end;
}
public static final byte[] Bry__class__mw_headline = Bry_.new_a7("mw-headline");
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hdr_data rv = new Xoh_hdr_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
}

View File

@@ -42,7 +42,7 @@ public class Xoh_hdr_html {
if (hdr_len > 0) { // NOTE: need to check hdr_len b/c it could be dangling
if (hdr.Hdr_end_manual() > 0) bfr.Add_byte_repeat(Byte_ascii.Eq, hdr.Hdr_end_manual()); // '='
if (cfg.Toc__show())
bfr.Add(Html_tag_.Span_rhs); // '</span>'
bfr.Add(Gfh_tag_.Span_rhs); // '</span>'
bfr.Add(Bry__hdr_rhs_bgn).Add_int(hdr_len, 1, 1); // '</h', '2'
bfr.Add(Bry__hdr_rhs_end); // '>\n'
}

View File

@@ -19,10 +19,11 @@ package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; impor
import gplx.core.brys.*; import gplx.core.threads.poolables.*; import gplx.xowa.wikis.ttls.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_hdr_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
public int Tid() {return Xoh_hzip_dict_.Tid__hdr;}
public String Key() {return Xoh_hzip_dict_.Key__hdr;}
public byte[] Hook() {return hook;} private byte[] hook;
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_hdr_parser data = (Xoh_hdr_parser)data_obj;
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_hdr_data data = (Xoh_hdr_data)data_obj;
boolean capt_rhs_exists = flag_bldr.Set_as_bool (Flag__capt_rhs_exists , data.Capt_rhs_exists());
boolean anch_is_diff = flag_bldr.Set_as_bool (Flag__anch_is_diff , data.Anch_is_diff());
int hdr_level = flag_bldr.Set_as_int (Flag__hdr_level , data.Hdr_level());
@@ -36,33 +37,20 @@ public class Xoh_hdr_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
hctx.Hzip__stat().Hdr_add(hdr_level);
return this;
}
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
int flag = rdr.Read_int_by_base85(1); flag_bldr.Decode(flag);
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
int flag = rdr.Read_hzip_int(1); flag_bldr.Decode(flag);
boolean capt_rhs_exists = flag_bldr.Get_as_bool(Flag__capt_rhs_exists);
boolean anch_is_diff = flag_bldr.Get_as_bool(Flag__anch_is_diff);
byte hdr_level = flag_bldr.Get_as_byte(Flag__hdr_level);
int capt_bgn = rdr.Pos(); int capt_end = rdr.Find_fwd_lr();
int anch_bgn = -1, anch_end = -1;
if (anch_is_diff) {
anch_bgn = rdr.Pos(); anch_end = rdr.Find_fwd_lr();
}
byte[] capt_manual_end = capt_rhs_exists ? rdr.Read_bry_to() : null;
bfr.Add(Bry__hdr__0).Add_byte_as_a7(hdr_level);
bfr.Add(Bry__hdr__1);
if (anch_is_diff)
bfr.Add_mid (src, anch_bgn, anch_end);
else
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, capt_bgn, capt_end);
bfr.Add(Bry__hdr__3);
if (capt_rhs_exists)
bfr.Add(capt_manual_end);
bfr.Add(Bry__hdr__4).Add_byte_as_a7(hdr_level);
bfr.Add_byte(Byte_ascii.Angle_end);
return rdr.Pos();
if (anch_is_diff) {anch_bgn = rdr.Pos(); anch_end = rdr.Find_fwd_lr();}
int capt_rhs_bgn = -1, capt_rhs_end = -1;
if (capt_rhs_exists) {capt_rhs_bgn = rdr.Pos(); capt_rhs_end = rdr.Find_fwd_lr();}
Xoh_hdr_data data = (Xoh_hdr_data)data_itm;
data.Init_by_decode(hdr_level, anch_is_diff, anch_bgn, anch_end, capt_bgn, capt_end, capt_rhs_bgn, capt_rhs_end);
}
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ (1, 1, 3);
private static final int // SERIALIZED
@@ -70,13 +58,6 @@ public class Xoh_hdr_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
, Flag__anch_is_diff = 1
, Flag__hdr_level = 2
;
private static final byte[]
Bry__hdr__0 = Bry_.new_a7("<h")
, Bry__hdr__1 = Bry_.new_a7("><span class=\"mw-headline\" id=\"")
, Bry__hdr__2 = Bry_.new_a7("\">")
, Bry__hdr__3 = Bry_.new_a7("</span>")
, Bry__hdr__4 = Bry_.new_a7("</h")
;
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hdr_hzip rv = new Xoh_hdr_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
}

View File

@@ -1,37 +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.sections.*;
public class Xoh_hdr_make {
public void Make(Bry_bfr bfr, Xoh_page hpg, byte[] src, Xoh_hdr_parser arg) {
// , int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch
// register section
int rng_bgn = arg.Src_bgn(), rng_end = arg.Src_end();
int level = arg.Hdr_level();
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"
byte[] capt = Bry_.Mid(src, arg.Capt_bgn(), arg.Capt_end());
byte[] anch = Bry_.Mid(src, arg.Anch_bgn(), arg.Anch_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,14 +23,10 @@ public class Xoh_hdr_make_tst {
String html = String_.Concat_lines_nl_skip_last
( "z"
, ""
, "<h2>"
, " <span class='mw-headline' id='A_1'>A 1</span>"
, "</h2>"
, "<h2><span class='mw-headline' id='A_1'>A 1</span></h2>"
, "a 1"
, ""
, "<h2>"
, " <span class='mw-headline' id='B'>B</span>"
, "</h2>"
, "<h2><span class='mw-headline' id='B'>B</span></h2>"
, "b"
);
fxt.Test__make(html, fxt.Page_chkr().Body_(html) // make sure body is same

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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.core.primitives.*; import gplx.core.brys.fmtrs.*; import gplx.core.threads.poolables.*; import gplx.core.brys.args.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*;
import gplx.xowa.htmls.sections.*; import gplx.xowa.htmls.core.hzips.*;
public class Xoh_hdr_wtr implements gplx.core.brys.Bfr_arg, Xoh_wtr_itm {
private int hdr_num; private byte[] hdr_id, hdr_content, hdr_capt_rhs;
private Xoh_page hpg;
public void Init_by_parse(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_hdr_data data) {
Init_by_decode(hpg, hctx, src, data);
this.Bfr_arg__add(bfr);
}
public boolean Init_by_decode(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_data_itm data_itm) {
this.hpg = hpg;
Xoh_hdr_data data = (Xoh_hdr_data)data_itm;
this.hdr_num = data.Hdr_level();
this.hdr_content = Bry_.Mid(src, data.Capt_bgn(), data.Capt_end());
if (data.Anch_is_diff())
hdr_id = Bry_.Mid(src, data.Anch_bgn(), data.Anch_end());
else
hdr_id = Bry_.Replace(hdr_content, Byte_ascii.Space, Byte_ascii.Underline);
hdr_capt_rhs = data.Capt_rhs_exists() ? Bry_.Mid(src, data.Capt_rhs_bgn(), data.Capt_rhs_end()) : Bry_.Empty;
return true;
}
public void Bfr_arg__add(Bry_bfr bfr) {
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, bfr.Bfr(), bfr.Len() - 2); // close previous section; -2 to skip "\n\n"
fmtr.Bld_bfr_many(bfr, hdr_num, hdr_id, hdr_content, hdr_capt_rhs);
section_mgr.Add(section_len, hdr_num, hdr_id, hdr_content).Content_bgn_(bfr.Len() + 1); // +1 to skip "\n"
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hdr_wtr rv = new Xoh_hdr_wtr(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
private static final Bry_fmtr fmtr = Bry_fmtr.new_
( "<h~{lvl}><span class=\"mw-headline\" id=\"~{id}\">~{content}</span>~{capt_rhs}</h~{lvl}>"
, "lvl", "id", "content", "capt_rhs");
}

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; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.threads.poolables.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_img_bare_data implements Xoh_data_itm {
public int Tid() {return Xoh_hzip_dict_.Tid__img_bare;}
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public int Dir_tid() {return dir_tid;} private int dir_tid;
public int Dir_bgn() {return dir_bgn;} private int dir_bgn;
public int Dir_end() {return dir_end;} private int dir_end;
public void Clear() {
this.src_bgn = src_end = dir_tid = dir_bgn = dir_end = -1;
}
public boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag img_head, Gfh_tag unused) {
this.src_bgn = img_head.Src_bgn(); this.src_end = img_head.Src_end();
Gfh_atr img_src_atr = img_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__src); if (img_src_atr.Val_dat_missing()) return false;
byte[] root_dir_bry = hctx.Fsys__root();
int root_dir_bgn = img_src_atr.Val_bgn();
int root_dir_end = root_dir_bgn + root_dir_bry.length;
if (Bry_.Match(src, root_dir_bgn, root_dir_end, root_dir_bry)) {
int hiero_dir_end = root_dir_end + Url__hiero.length;
if (Bry_.Match(src, root_dir_end, hiero_dir_end, Url__hiero)) {
dir_tid = Dir_tid__hiero;
dir_bgn = root_dir_bgn;
dir_end = hiero_dir_end;
return true;
}
}
return false;
}
public void Init_by_decode(int src_bgn, int src_end, int dir_tid, int dir_bgn, int dir_end) {
this.src_bgn = src_bgn; this.src_end = src_end; this.dir_tid = dir_tid; this.dir_bgn = dir_bgn; this.dir_end = dir_end;
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_bare_data rv = new Xoh_img_bare_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
public static final byte[] Url__hiero = Bry_.new_a7("bin/any/xowa/xtns/Wikihiero/img/hiero_");
public static final int Dir_tid__null = -1, Dir_tid__hiero = 0;
}

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.core.brys.*; import gplx.core.threads.poolables.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_img_bare_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
public int Tid() {return Xoh_hzip_dict_.Tid__img_bare;}
public String Key() {return Xoh_hzip_dict_.Key__img_bare;}
public byte[] Hook() {return hook;} private byte[] hook;
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_img_bare_data data = (Xoh_img_bare_data)data_obj;
flag_bldr.Set(Flag__dir_tid , data.Dir_tid());
bfr.Add(hook);
Xoh_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
bfr.Add_hzip_mid(src, data.Src_bgn(), data.Dir_bgn());
bfr.Add_hzip_mid(src, data.Dir_end(), data.Src_end());
return this;
}
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
Xoh_img_bare_data data = (Xoh_img_bare_data)data_itm; data.Clear();
int flag = rdr.Read_hzip_int(1); flag_bldr.Decode(flag);
int dir_tid = flag_bldr.Get_as_int(Flag__dir_tid);
int tag_0_bgn = rdr.Pos(), tag_0_end = rdr.Find_fwd_lr();
int tag_1_bgn = rdr.Pos(), tag_1_end = rdr.Find_fwd_lr();
data.Init_by_decode(tag_0_bgn, tag_1_end, dir_tid, tag_0_end, tag_1_bgn);
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_bare_hzip rv = new Xoh_img_bare_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(2);
private static final int // SERIALIZED
Flag__dir_tid = 0
;
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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.*;
public class Xoh_img_bare_hzip__tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Before public void Clear() {fxt.Clear();}
@Test public void Hiero() {
fxt.Test__bicode
( "~(!<img style=\"margin: 1px; height: 11px;\" src=\"~X1.png\" title=\"X1 [t]\" alt=\"t\">~"
, "<img style='margin: 1px; height: 11px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_X1.png' title='X1 [t]' alt='t'>"
);
}
}

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.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.core.threads.poolables.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_img_bare_wtr implements Bfr_arg, Xoh_wtr_itm {
private byte[] src;
private Xoh_img_bare_data data_itm;
private Xoh_hdoc_ctx hctx;
public void Init_by_parse(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_img_bare_data data) {
this.src = src; this.hctx = hctx;
this.data_itm = data;
}
public boolean Init_by_decode(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_data_itm data_itm) {
this.src = src; this.hctx = hctx;
this.data_itm = (Xoh_img_bare_data)data_itm;
return true;
}
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add_mid(src, data_itm.Src_bgn(), data_itm.Dir_bgn());
bfr.Add(hctx.Fsys__root()).Add(Xoh_img_bare_data.Url__hiero);
bfr.Add_mid(src, data_itm.Dir_end(), data_itm.Src_end());
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_bare_wtr rv = new Xoh_img_bare_wtr(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
}

View File

@@ -1,52 +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.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.core.wkrs.imgs.atrs.*;
import gplx.xowa.files.*;
public class Xoh_img_bldr {
public Xoh_img_wtr Wtr() {return wtr;} private final Xoh_img_wtr wtr = new Xoh_img_wtr();
public Xof_fsdb_itm Fsdb_itm() {return fsdb_itm;} private Xof_fsdb_itm fsdb_itm;
public void Make_by_parse(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_img_parser arg) {
Make( bfr, hpg, hctx, src, arg.Img_src().File_ttl_bry(), arg.Img_xoimg(), arg.Img_xoimg().Val_dat_exists()
, arg.Rel_nofollow_exists(), arg.Anch_href().Atr(), arg.Anch_cls().Atr(), arg.Anch_title()
, arg.Img_w(), arg.Img_h(), arg.Img_src().Atr(), arg.Img_cls().Atr(), arg.Img_alt());
wtr.Bfr_arg__add(bfr);
}
public void Make(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, byte[] lnki_ttl, Xoh_img_xoimg_parser img_xoimg, boolean img_xoimg_exists
, boolean anch_rel_is_nofollow, Bfr_arg anch_href, Bfr_arg anch_cls, Bfr_arg anch_ttl
, int img_w, int img_h, Bfr_arg img_src, Bfr_arg img_cls, Bfr_arg img_alt) {
wtr.Clear();
this.fsdb_itm = hpg.Img_mgr().Make_img();
if (img_xoimg_exists) {
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), lnki_ttl, img_xoimg.Lnki_type(), img_xoimg.Lnki_upright(), img_xoimg.Lnki_w(), img_xoimg.Lnki_h(), img_xoimg.Lnki_time(), img_xoimg.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
hctx.File__mgr().Check_cache(fsdb_itm);
wtr.Img_xoimg_(img_xoimg);
wtr.Img_src_empty_().Img_w_(0).Img_h_(0);
}
else if (img_w != -1) {
wtr.Img_w_(img_w).Img_h_(img_h).Img_src_(img_src);
}
if (anch_rel_is_nofollow) wtr.Anch_rel_nofollow_();
wtr.Anch_href_(anch_href).Anch_cls_(anch_cls).Anch_title_(anch_ttl).Anch_xowa_title_(lnki_ttl);
if (!hctx.Mode_is_diff())
wtr.Img_id_(Xoh_img_mgr.Bry__html_uid, fsdb_itm.Html_uid());
wtr.Img_alt_(img_alt).Img_cls_(img_cls);
}
}

View File

@@ -0,0 +1,105 @@
/*
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.primitives.*; import gplx.core.brys.*; import gplx.core.threads.poolables.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; 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.htmls.core.hzips.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.files.*;
public class Xoh_img_data implements Xoh_data_itm {
public int Tid() {return Xoh_hzip_dict_.Tid__img;}
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public Xoh_anch_href_data Anch_href() {return anch_href;} private Xoh_anch_href_data anch_href = new Xoh_anch_href_data();
public Xoh_anch_cls_data Anch_cls() {return anch_cls;} private Xoh_anch_cls_data anch_cls = new Xoh_anch_cls_data();
public boolean Anch_rel_nofollow_exists() {return anch_rel_is_nofollow;} private boolean anch_rel_is_nofollow;
public int Anch_title_bgn() {return anch_title_bgn;} private int anch_title_bgn;
public int Anch_title_end() {return anch_title_end;} private int anch_title_end;
public boolean Anch_title_exists() {return anch_title_end != -1;}
public Bry_obj_ref Anch_page() {return anch_page;} private Bry_obj_ref anch_page = Bry_obj_ref.New_empty();
public Xoh_img_src_data Img_src() {return img_src;} private final Xoh_img_src_data img_src = new Xoh_img_src_data();
public Xoh_img_cls_data Img_cls() {return img_cls;} private final Xoh_img_cls_data img_cls = new Xoh_img_cls_data();
public Xoh_img_xoimg_data Img_xoimg() {return img_xoimg;} private Xoh_img_xoimg_data img_xoimg = new Xoh_img_xoimg_data();
public int Img_alt_bgn() {return img_alt_bgn;} private int img_alt_bgn;
public int Img_alt_end() {return img_alt_end;} private int img_alt_end;
public boolean Img_alt__diff__anch_title() {return img_alt__diff_anch_title;} private boolean img_alt__diff_anch_title;
public int Img_w() {return img_w;} private int img_w;
public int Img_h() {return img_h;} private int img_h;
public boolean Img_w__diff__file_w() {return img_w != img_src.File_w();}
public boolean Img_is_vid() {return img_is_vid;} private boolean img_is_vid;
public void Clear() {
this.img_alt__diff_anch_title = anch_rel_is_nofollow = false;
this.src_bgn = src_end = anch_title_bgn = anch_title_end = img_w = img_h = img_alt_bgn = img_alt_end = -1;
this.img_is_vid = false;
anch_href.Clear(); anch_cls.Clear();
img_src.Clear(); img_cls.Clear(); img_xoimg.Clear();
}
public boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag anch_head, Gfh_tag unused) {
if (anch_head.Name_id() == Gfh_tag_.Id__div) { // video / audio
img_is_vid = true;
tag_rdr.Tag__move_fwd_head(); // next <div>
anch_head = tag_rdr.Tag__move_fwd_head(); // next <div>
}
Bry_err_wkr err_wkr = tag_rdr.Err_wkr();
this.src_bgn = anch_head.Src_bgn(); // <a
if (!anch_href.Parse(err_wkr, hctx, src, anch_head)) return false; // href='/wiki/File:A.png'
if (!anch_cls.Parse(err_wkr, src, anch_head)) return false; // class='image'
Gfh_atr anch_title = anch_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__title); // title='abc'
anch_title_bgn = anch_title.Val_bgn(); anch_title_end = anch_title.Val_end();
Gfh_atr xowa_title = anch_head.Atrs__get_by_or_empty(Bry__atr__xowa_title); // xowa_title='A.png'
if (xowa_title.Val_dat_exists()) anch_page.Val_(xowa_title.Val());
Gfh_tag img_tag = tag_rdr.Tag__move_fwd_head().Chk_name_or_fail(Gfh_tag_.Id__img); // <img
img_xoimg.Parse(err_wkr, src, img_tag); // data-xoimg='...'
this.img_w = img_tag.Atrs__get_as_int_or(Gfh_atr_.Bry__width, Xof_img_size.Size__neg1); // width='220'
this.img_h = img_tag.Atrs__get_as_int_or(Gfh_atr_.Bry__height, Xof_img_size.Size__neg1); // height='110'
Gfh_atr img_alt = img_tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__alt); // alt='File:A.png'
img_alt_bgn = img_alt.Val_bgn(); img_alt_end = img_alt.Val_end();
img_cls.Init_by_parse(err_wkr, src, img_tag); // class='thumbborder'
img_alt__diff_anch_title = !Bry_.Match(src, img_alt_bgn, img_alt_end, src, anch_title_bgn, anch_title_end);
if (!img_src.Parse(err_wkr, hctx, hctx.Wiki__domain_bry(), img_tag)) return false; // src='...'
if (anch_page.Val_is_empty()) {
anch_page.Val_(img_src.File_ttl_bry());
if (anch_page.Val_is_empty())
anch_page.Val_(anch_href.Ttl_page_db());
}
Gfh_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__a); // </a>
this.src_end = anch_tail.Src_end();
if (anch_href.Site_exists()) {
Xow_domain_itm itm = Xow_domain_itm_.parse(Bry_.Mid(src, anch_href.Site_bgn(), anch_href.Site_end()));
anch_rel_is_nofollow = itm.Domain_type_id() == Xow_domain_tid_.Int__other;
}
if (img_is_vid) {
tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__div);
anch_head = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__div);
src_end = anch_head.Src_end();
}
return true;
}
public void Init_by_decode(boolean anch_rel_is_nofollow, int anch_title_bgn, int anch_title_end, boolean img_is_vid, int img_w, int img_h, int img_alt_bgn, int img_alt_end) {
this.anch_rel_is_nofollow = anch_rel_is_nofollow;
this.anch_title_bgn = anch_title_bgn; this.anch_title_end = anch_title_end;
this.img_is_vid = img_is_vid;
this.img_w = img_w; this.img_h = img_h;
this.img_alt_bgn = img_alt_bgn; this.img_alt_end = img_alt_end;
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_data rv = new Xoh_img_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
public static final byte[]
Bry__cls__anch__image = Bry_.new_a7("image")
, Bry__cls__img__thumbimage = Bry_.new_a7("thumbimage")
, Bry__atr__xowa_title = Bry_.new_a7("xowa_title")
;
}

View File

@@ -17,42 +17,35 @@ 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.primitives.*; import gplx.core.brys.*; import gplx.core.threads.poolables.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.langs.htmls.encoders.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
private final Bry_bfr tmp_bfr = Bry_bfr.new_(32);
private final Xoh_img_xoimg_hzip xoimg = new Xoh_img_xoimg_hzip();
public int Tid() {return Xoh_hzip_dict_.Tid__img;}
public String Key() {return Xoh_hzip_dict_.Key__img;}
public byte[] Hook() {return hook;} private byte[] hook;
private final Xoh_img_xoimg_parser xoimg_parser = new Xoh_img_xoimg_parser();
private final Bry_bfr tmp_bfr = Bry_bfr.new_(32);
public Xoh_img_bldr Bldr() {return bldr;} private Xoh_img_bldr bldr = new Xoh_img_bldr();
public Bfr_arg__href Anch_href_arg() {return anch_href_arg;} private final Bfr_arg__href anch_href_arg = new Bfr_arg__href();
public Xoh_img_xoimg_hzip Xoimg() {return xoimg;} private final Xoh_img_xoimg_hzip xoimg = new Xoh_img_xoimg_hzip();
private final Bry_obj_ref
anch_cls_mid = Bry_obj_ref.New_empty()
, anch_title_mid = Bry_obj_ref.New_empty()
, anch_href_mid = Bry_obj_ref.New_empty()
, img_alt_mid = Bry_obj_ref.New_empty()
, img_src_mid = Bry_obj_ref.New_empty()
, img_cls_mid = Bry_obj_ref.New_empty()
;
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_img_parser data = (Xoh_img_parser)data_obj;
Xoh_anch_href_itm anch_href = data.Anch_href();
public Xoh_img_wtr Wtr() {return wtr;} private Xoh_img_wtr wtr = new Xoh_img_wtr();
public byte[] Anch_href_bry() {return anch_href_bry;} private byte[] anch_href_bry;
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_img_data data = (Xoh_img_data)data_obj;
Xoh_anch_href_data anch_href = data.Anch_href();
Bry_obj_ref anch_page = data.Anch_page();
byte anch_href_tid = anch_href.Tid();
boolean anch__ns_is_custom = anch_href.Ttl_ns_custom() != null;
boolean anch__ns_id_needs_saving = Xoh_anch_href_itm.Ns_exists(anch_href.Tid()) && anch_href.Ttl_ns_id() != Xow_ns_.Tid__file;
Html_atr anch_title = data.Anch_title();
Xoh_img_xoimg_parser img_xoimg = data.Img_xoimg();
Xoh_img_cls_parser img_cls = data.Img_cls();
Xoh_img_src_parser img_src = data.Img_src();
boolean anch__ns_id_needs_saving = Xoh_anch_href_data.Ns_exists(anch_href.Tid()) && anch_href.Ttl_ns_id() != Xow_ns_.Tid__file;
boolean anch_title_exists = data.Anch_title_exists();
Xoh_img_xoimg_data img_xoimg = data.Img_xoimg();
Xoh_img_cls_data img_cls = data.Img_cls();
Xoh_img_src_data img_src = data.Img_src();
boolean img__alt_diff_from_anch_title = data.Img_alt__diff__anch_title();
boolean file__src_exists = !img_xoimg.Val_dat_exists();
boolean anch_href_diff_file = !Bry_.Match(anch_page.Val(), anch_page.Val_bgn(), anch_page.Val_end(), anch_href.Ttl_page_db());
flag_bldr.Set(Flag__img__is_vid , data.Img_is_vid());
flag_bldr.Set(Flag__file__w_diff_from_html , file__src_exists && data.Img_w__diff__file_w());
flag_bldr.Set(Flag__file__time_exists , file__src_exists && img_src.File_time_exists());
flag_bldr.Set(Flag__file__page_exists , file__src_exists && img_src.File_page_exists());
@@ -65,7 +58,7 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
flag_bldr.Set(Flag__anch__ns_id_needs_saving , anch__ns_id_needs_saving);
flag_bldr.Set(Flag__img__alt_diff_from_anch_title , img__alt_diff_from_anch_title);
flag_bldr.Set(Flag__anch__href_diff_file , anch_href_diff_file);
flag_bldr.Set(Flag__anch__title_missing , anch_title.Val_dat_missing());
flag_bldr.Set(Flag__anch__title_missing , !anch_title_exists);
flag_bldr.Set(Flag__img__cls_tid , img_cls.Cls_tid());
flag_bldr.Set(Flag__anch__href_tid , anch_href.Tid());
// Tfds.Dbg(flag_bldr.Encode(), Array_.To_str(flag_bldr.Val_ary()));
@@ -73,29 +66,28 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
if (wkr_is_root) bfr.Add(hook);
Xoh_hzip_int_.Encode(2, bfr, flag_bldr.Encode());
switch (anch_href_tid) {
case Xoh_anch_href_itm.Tid__inet:
anch_href_mid.Mid_(src, anch_href.Rng_bgn(), anch_href.Rng_end());
case Xoh_anch_href_data.Tid__inet:
bfr.Add_mid(src, anch_href.Rng_bgn(), anch_href.Rng_end());
break;
case Xoh_anch_href_itm.Tid__site:
anch_href_mid.Val_(tmp_bfr.Add_mid(src, anch_href.Site_bgn(), anch_href.Site_end()).Add_byte(Byte_ascii.Pipe).Add(anch_href.Ttl_page_db()).To_bry_and_clear());
case Xoh_anch_href_data.Tid__site:
bfr.Add_mid(src, anch_href.Site_bgn(), anch_href.Site_end()).Add_byte(Byte_ascii.Pipe).Add(anch_href.Ttl_page_db());
break;
case Xoh_anch_href_itm.Tid__wiki:
case Xoh_anch_href_itm.Tid__anch:
anch_href_mid.Val_(anch_href.Ttl_page_db());
case Xoh_anch_href_data.Tid__wiki:
case Xoh_anch_href_data.Tid__anch:
bfr.Add(anch_href.Ttl_page_db());
break;
}
bfr.Add_bry_ref_obj(anch_href_mid);
bfr.Add_byte(Xoh_hzip_dict_.Escape);
if (anch_href_diff_file) {
data.Anch_page().Bfr_arg__add(bfr);
bfr.Add_byte(Xoh_hzip_dict_.Escape);
}
switch (anch_href_tid) {
case Xoh_anch_href_itm.Tid__anch:
case Xoh_anch_href_itm.Tid__inet:
case Xoh_anch_href_data.Tid__anch:
case Xoh_anch_href_data.Tid__inet:
break;
case Xoh_anch_href_itm.Tid__wiki:
case Xoh_anch_href_itm.Tid__site:
case Xoh_anch_href_data.Tid__wiki:
case Xoh_anch_href_data.Tid__site:
if (anch__ns_id_needs_saving)
Xoh_lnki_dict_.Ns_encode(bfr, anch_href.Ttl_ns_id());
break;
@@ -110,15 +102,15 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
}
else
xoimg.Encode(bfr, hctx.Hzip__stat(), src, img_xoimg);
if (anch_title.Val_dat_exists()) bfr.Add_mid(src, anch_title.Val_bgn(), anch_title.Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
if (img__alt_diff_from_anch_title) bfr.Add_mid(src, data.Img_alt().Val_bgn(), data.Img_alt().Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
if (anch_title_exists) bfr.Add_mid(src, data.Anch_title_bgn(), data.Anch_title_end()).Add_byte(Xoh_hzip_dict_.Escape);
if (img__alt_diff_from_anch_title) bfr.Add_mid(src, data.Img_alt_bgn(), data.Img_alt_end()).Add_byte(Xoh_hzip_dict_.Escape);
if (img_cls.Other_exists()) bfr.Add_mid(src, img_cls.Other_bgn(), img_cls.Other_end()).Add_byte(Xoh_hzip_dict_.Escape);
return this;
}
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
// decode rdr
int flag = rdr.Read_int_by_base85(2);
flag_bldr.Decode(flag);
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
Xoh_img_data data = (Xoh_img_data)data_itm; data.Clear();
int flag = rdr.Read_hzip_int(2); flag_bldr.Decode(flag);
boolean file__is_orig = flag_bldr.Get_as_bool(Flag__file__is_orig);
boolean file__repo_is_local = flag_bldr.Get_as_bool(Flag__file__repo_is_local);
boolean file__src_exists = flag_bldr.Get_as_bool(Flag__file__src_exists);
@@ -129,16 +121,17 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
boolean img__alt_diff_from_anch_title = flag_bldr.Get_as_bool(Flag__img__alt_diff_from_anch_title);
boolean anch_href_diff_file = flag_bldr.Get_as_bool(Flag__anch__href_diff_file);
boolean anch__title_missing = flag_bldr.Get_as_bool(Flag__anch__title_missing);
boolean img_is_vid = flag_bldr.Get_as_bool(Flag__img__is_vid);
int img_cls = flag_bldr.Get_as_int(Flag__img__cls_tid);
int anch__href_tid = flag_bldr.Get_as_int(Flag__anch__href_tid);
byte[] page_db = rdr.Read_bry_to();
byte[] site_bry = null;
switch (anch__href_tid) {
case Xoh_anch_href_itm.Tid__anch:
case Xoh_anch_href_itm.Tid__inet:
case Xoh_anch_href_itm.Tid__wiki:
case Xoh_anch_href_data.Tid__anch:
case Xoh_anch_href_data.Tid__inet:
case Xoh_anch_href_data.Tid__wiki:
break;
case Xoh_anch_href_itm.Tid__site:
case Xoh_anch_href_data.Tid__site:
int pipe_pos = Bry_find_.Find_fwd(page_db, Byte_ascii.Pipe);
site_bry = Bry_.Mid(page_db, 0, pipe_pos);
page_db = Bry_.Mid(page_db, pipe_pos + 1);
@@ -155,14 +148,13 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
ns_custom_end = rdr.Find_fwd_lr();
}
int img_w = -1, img_h = -1, file_time = -1, file_page = -1;
xoimg_parser.Clear();
if (file__src_exists) {
img_w = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
img_h = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
}
else {
xoimg.Decode(bfr, hctx, hpg, rdr, src, xoimg_parser);
img_w = rdr.Read_hzip_int(2) - Xoh_hzip_int_.Neg_1_adj;
img_h = rdr.Read_hzip_int(2) - Xoh_hzip_int_.Neg_1_adj;
}
else
xoimg.Decode(bfr, hctx, hpg, rdr, src, data.Img_xoimg());
int anch_title_bgn = -1, anch_title_end = -1;
if (!anch__title_missing) {
anch_title_bgn = rdr.Pos();
@@ -177,23 +169,30 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
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());
int rv = rdr.Move_to(rdr.Pos());
int img_cls_other_bgn = -1; int img_cls_other_end = -1;
if (img__cls_other_exists) {
img_cls_other_bgn = rdr.Pos();
img_cls_other_end = rdr.Find_fwd_lr();
}
// transform values
boolean anch_rel_is_nofollow = false;
if (anch__href_tid == Xoh_anch_href_itm.Tid__inet) {
if (anch__href_tid == Xoh_anch_href_data.Tid__inet) {// external links should get rel=nofollow
Gfo_url_encoder_.Href.Encode(tmp_bfr, page_db);
anch_rel_is_nofollow = true;
if (Bry_.Len_gt_0(page_db)) // NOTE: page_db == "" for Media links; EX:[[File:A.png|link=file:///C:/A.ogg]] -> <a href='' class='image'>
anch_rel_is_nofollow = true;
}
else {
if (anch__href_tid == Xoh_anch_href_itm.Tid__site)
if (anch__href_tid == Xoh_anch_href_data.Tid__site)
tmp_bfr.Add(Xoh_href_.Bry__site).Add(site_bry);
if (anch__ns_id_needs_saving) {
Xoa_ttl anch_href_ttl = hctx.Wiki__ttl_parser().Ttl_parse(anch_href_ns, page_db);
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(anch_href_ttl.Full_url());
byte[] page_ttl_bry = page_db;
if ( anch__href_tid == Xoh_anch_href_data.Tid__wiki // if wiki, parse ttl
|| anch_href_ns != Xow_ns_.Tid__main) { // or if site and !main_ns; handles /site/en.wiktionary.org/wiki/Special:Search but not /site/creativecommons.org/wiki/by/2.5; DATE:2015-12-28
Xoa_ttl anch_href_ttl = hctx.Wiki__ttl_parser().Ttl_parse(anch_href_ns, page_db);
page_ttl_bry = anch_href_ttl.Full_url();
}
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(page_ttl_bry);
}
else {
byte[] ns_bry = anch__ns_is_custom ? Bry_.Mid(src, ns_custom_bgn, ns_custom_end) : Xow_ns_.Bry__file;
@@ -201,43 +200,39 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
Gfo_url_encoder_.Href.Encode(tmp_bfr, page_db);
}
}
anch_href_arg.Set_by_raw(tmp_bfr.To_bry_and_clear());
this.anch_href_bry = tmp_bfr.To_bry_and_clear();
// NOTE: src must go underneath ttl
Xof_url_bldr url_bldr = hctx.File__url_bldr();
url_bldr.Init_by_root(file__repo_is_local ? hctx.Fsys__file__wiki() : hctx.Fsys__file__comm(), Byte_ascii.Slash, false, false, Md5_depth);
url_bldr.Init_by_itm(file__is_orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, file_db, Xof_file_wkr_.Md5(file_db), Xof_ext_.new_by_ttl_(file_db), img_w, file_time, file_page);
byte[] img_src = url_bldr.Xto_bry();
anch_cls_mid.Val_(Xoh_anch_cls_.To_val(anch__cls_tid));
if (!anch__title_missing) anch_title_mid.Mid_(src, anch_title_bgn, anch_title_end); else {anch_title_mid.Val_(null);} // if (anch_title_bgn == anch_title_end) anch_title_mid.Val_(null);
img_alt_mid.Mid_(src, img_alt_bgn, img_alt_end); if (img_alt_mid.Val_is_empty()) img_alt_mid.Val_(Bry_.Empty);
img_src_mid.Val_(img_src);
img_cls_mid.Val_(Xoh_img_cls_.To_val_or_null(img_cls, img_cls_other));
bldr.Make(bfr, hpg, hctx, src, file_db, xoimg_parser, !file__src_exists, anch_rel_is_nofollow, anch_href_arg, anch_cls_mid, anch_title_mid, img_w, img_h, img_src_mid, img_cls_mid, img_alt_mid);
if (wkr_is_root) bldr.Wtr().Bfr_arg__add(bfr);
return rv;
data.Init_by_decode(anch_rel_is_nofollow, anch_title_bgn, anch_title_end, img_is_vid, img_w, img_h, img_alt_bgn, img_alt_end);
data.Anch_href().Init_by_decode(anch_href_bry);
data.Anch_cls().Init_by_decode(anch__cls_tid);
data.Img_cls().Init_by_decode(src, img_cls, img_cls_other_bgn, img_cls_other_end);
data.Img_src().Init_by_decode(file_db, url_bldr.Xto_bry());
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_hzip rv = new Xoh_img_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
public static int Md5_depth = 2;
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1, 1, 1 , 1, 1, 1, 1 , 2, 1, 1, 1 , 1, 2, 2);
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1, 1, 1 , 1 , 1, 1, 1 , 1 , 2, 1, 1 , 1, 1, 2, 2);
private static final int // SERIALIZED
Flag__file__w_diff_from_html = 0
, Flag__file__time_exists = 1
, Flag__file__page_exists = 2
, Flag__file__is_orig = 3
, Flag__file__repo_is_local = 4
, Flag__file__src_exists = 5
, Flag__img__cls_other_exists = 6
, Flag__anch__ns_is_custom = 7
, Flag__anch__cls_tid = 8 // none, image
, Flag__anch__ns_id_needs_saving = 9
, Flag__img__alt_diff_from_anch_title = 10
, Flag__anch__href_diff_file = 11
, Flag__anch__title_missing = 12
, Flag__img__cls_tid = 13 // none, thumbimage, thumbborder
, Flag__anch__href_tid = 14 // wiki, site, anch, inet
Flag__img__is_vid = 0
, Flag__file__w_diff_from_html = 1
, Flag__file__time_exists = 2
, Flag__file__page_exists = 3
, Flag__file__is_orig = 4
, Flag__file__repo_is_local = 5
, Flag__file__src_exists = 6
, Flag__img__cls_other_exists = 7
, Flag__anch__ns_is_custom = 8
, Flag__anch__cls_tid = 9 // none, image
, Flag__anch__ns_id_needs_saving = 10
, Flag__img__alt_diff_from_anch_title = 11
, Flag__anch__href_diff_file = 12
, Flag__anch__title_missing = 13
, Flag__img__cls_tid = 14 // none, thumbimage, thumbborder
, Flag__anch__href_tid = 15 // wiki, site, anch, inet
;
}

View File

@@ -18,65 +18,97 @@ 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.*;
public class Xoh_img_hzip__dump__tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Before public void Clear() {fxt.Clear();}
@Test public void Basic() { // [[File:A.png|border|class=other|220px|abc]]
fxt.Test__bicode
( "~%!!A.png~)#Sabc~"
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
);
}
@Test public void Anch() { // [[File:A.png#b|abc]]
fxt.Test__bicode
( "~%\"<A.png#file~A.png~)#Sabc~"
, "<a href='/wiki/File:A.png#file' class='image' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
, "<a href='/wiki/File:A.png#file' class='image' xowa_title='A.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
);
}
@Test public void Link__cs() { // [[File:A.png|link=File:a.ogg|abc]]
fxt.Test__bicode
( "~%!Aa.ogg~A.png~)#Sabc~"
, "<a href='/wiki/File:a.ogg' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
, "<a href='/wiki/File:a.ogg' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
);
}
@Test public void Href__encoding() { // [[File:Aéb.png|abc]]
fxt.Test__bicode
( "~%!qAéb.png~)#Sabc~"
, "<a href='/wiki/File:A%C3%A9b.png' class='image' xowa_title='Aéb.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
, "<a href='/wiki/File:A%C3%A9b.png' class='image' xowa_title='Aéb.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
);
}
@Test public void Href__encoding__link() { // [[File:Aéb.png|abc|link=Aéb]]
fxt.Test__bicode
( "~%#gAéb~Aéb.png~#)#Sabc~"
, "<a href='/wiki/A%C3%A9b' class='image' xowa_title='Aéb.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
, "<a href='/wiki/A%C3%A9b' class='image' xowa_title='Aéb.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
);
}
@Test public void Href__apos() { // [[File:A'b.png|border|link=A'b_link|A'b_capt]]
String html = "<a href=\"/wiki/A%27b_link\" class=\"image\" xowa_title=\"A'b.png\"><img id=\"xoimg_0\" data-xoimg=\"0|220|-1|-1|-1|-1\" src=\"\" width=\"0\" height=\"0\" class=\"thumbborder\" alt=\"A'b_capt\"></a>";
String html = "<a href=\"/wiki/A%27b_link\" class=\"image\" xowa_title=\"A'b.png\"><img data-xoimg=\"0|220|-1|-1|-1|-1\" src=\"\" width=\"0\" height=\"0\" class=\"thumbborder\" alt=\"A'b_capt\"></a>";
fxt.Test__bicode_raw("~%#oA'b_link~A'b.png~#)#SA'b_capt~", html, html);
}
@Test public void Link__wm__n() { // [[File:A.png|link=http://a.org|abc]]
fxt.Test__bicode
( "~%!Dhttp://a.org~A.png~)#Sabc~"
, "<a href='http://a.org' rel='nofollow' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
, "<a href='http://a.org' rel='nofollow' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
);
}
@Test public void Link__wm__y() { // [[File:A.png|link=http://en.wikitionary.org/wiki/Special:Search/A|abc]]
fxt.Test__bicode
( "~%\"men.wiktionary.org|Search/A~A.png~\")#Sabc~"
, "<a href='/site/en.wiktionary.org/wiki/Special:Search/A' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
, "<a href='/site/en.wiktionary.org/wiki/Special:Search/A' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
);
}
// lhs='<a href="/site/en.wiktionary.org/wiki/Special:Search/A" class="image" title="B" xowa_title="Commons-logo.svg"><img data-xoimg="0|40|40|-1|-1|-1" src="" width="0" height="0" alt="B"></a>
@Test public void Link__wm__n_2() { // [[File:A.png|link=creativecommons:by/2.5]]
fxt.Test__bicode
( "~%#(creativecommons.org|by/2.5/~CC-BY-icon-80x15.png~#)!q"
, "<a href='/site/creativecommons.org/wiki/by/2.5/' class='image' xowa_title='CC-BY-icon-80x15.png'><img data-xoimg='0|80|-1|-1|-1|-1' src='' width='0' height='0' alt=''></a>"
);
}
@Test public void Link__media() { // [[File:A.png|link=file:///C:/A.ogg]]
fxt.Test__bicode
( "~%!D~A.ogg~)!,B~"
, "<a href='' class='image' title='B' xowa_title='A.ogg'><img data-xoimg='0|11|-1|-1|-1|-1' src='' width='0' height='0' alt='B'></a>"
);
}
// @Test public void Link__encoding() { // [[File:A.svg|24px|text-top|link=wikt:𬖾|𬖾]]; PAGE:en.w:Pho
// fxt.Test__bicode
// ( "~%#Xen.wiktionary.org|𬖾~A.png~#)!,abc~B~"
// , "<a href='/site/en.wiktionary.org/wiki/%F0%AC%96%BE' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|11|-1|-1|-1|-1' src='' width='0' height='0' alt='B'></a>"
// );
// }
@Test public void Href__image() { // [[Image:A.png|abc]]
fxt.Test__bicode
( "~%-%A.png~Image~)#Sabc~"
, "<a href='/wiki/Image:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
, "<a href='/wiki/Image:A.png' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
);
}
@Test public void Missing() { // PURPOSE: bad dump shouldn't write corrupt data
fxt.Test__bicode
( "%|\"\\QA.png!!!!A"
, "<a href='/wiki/File:A.png' class='image' title='A' xowa_title='A.png'><img id='xoimg_0' alt='A'></a>"
, "<a href='/wiki/File:A.png' class='image' title='A' xowa_title='A.png'><img alt='A'></a>"
);
}
@Test public void Manual_img_cls() { // PURPOSE: handle manual class; EX: [[File:A.png|class=noviewer]] en.w:ASCII; DATE:2015-12-21
fxt.Test__bicode
( "~%95A.png~)#Sabc~cls1~"
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' class='cls1' alt='abc'></a>"
);
}
@Test public void Video() { // [[File:A.ogv]]
fxt.Test__bicode
( "%|E9eA.ogv~!A.ogv~~", String_.Concat_lines_nl_skip_last
( "<div class='xowa_media_div'>"
, "<div><a href='/wiki/File:A.ogv' class='image' title='A.ogv' xowa_title='A.ogv'><img data-xoimg='0|-1|-1|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "<div><a href='' xowa_title='A.ogv' class='xowa_anchor_button' style='width:218px;max-width:220px;'><img src='' width='22' height='22' alt='Play sound'></a></div>"
, "</div>"
));
}
}

View File

@@ -32,5 +32,5 @@ public class Xoh_img_hzip__view__tst {
, "<a href='/wiki/B' class='image' title='B' xowa_title='A.png'><img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' alt='A.png'></a>"
);
}
// link_site: [[File:A.png|link=//en.wiktionary.org/B]] -> [[File:Wiktionary-logo-en.svg|25x25px|link=//en.wiktionary.org/wiki/Special:Search/Earth|Search Wiktionary]] -> <a href="/site/en.wiktionary.org/wiki/Special:Search/Earth" rel="nofollow" title="Search Wiktionary" xowa_title="Wiktionary-logo-en.svg"><img id="xowa_file_img_88" alt="Search Wiktionary" src="file:///J:/xowa/file/commons.wikimedia.org/thumb/f/8/c/4/Wiktionary-logo-en.svg/23px.png" width="23" height="25"></a>
// 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="xoimg_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

@@ -29,6 +29,15 @@ public class Xoh_img_make__dump__tst {
.Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1)
);
}
@Test public void Utf8() {
String
orig = "<a href='/wiki/File:A%C3%A9_b.png' class='image' title='abc' xowa_title='Aé_b.png'><img data-xoimg='0|220|110|0.5|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A%C3%A9_b.png/220px.png' width='220' height='110' alt='abc'></a>"
, expd = "<a href='/wiki/File:A%C3%A9_b.png' class='image' title='abc' xowa_title='A%C3%A9_b.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
;
fxt.Test__make(orig, fxt.Page_chkr().Body_(expd)
.Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1)
);
}
// @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>"

View File

@@ -1,85 +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.imgs; 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.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.files.*;
public class Xoh_img_parser {
private byte[] src;
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public Xoh_anch_href_itm Anch_href() {return anch_href;} private Xoh_anch_href_itm anch_href = new Xoh_anch_href_itm();
public Xoh_anch_cls_parser Anch_cls() {return anch_cls;} private Xoh_anch_cls_parser anch_cls = new Xoh_anch_cls_parser();
public Html_atr Anch_title() {return anch_title;} private Html_atr anch_title;
public Bry_obj_ref Anch_page() {return anch_page;} private Bry_obj_ref anch_page = Bry_obj_ref.New_empty();
public Xoh_img_src_parser Img_src() {return img_src;} private final Xoh_img_src_parser img_src = new Xoh_img_src_parser();
public Xoh_img_cls_parser Img_cls() {return img_cls;} private final Xoh_img_cls_parser img_cls = new Xoh_img_cls_parser();
public Xoh_img_xoimg_parser Img_xoimg() {return img_xoimg_parser;} private Xoh_img_xoimg_parser img_xoimg_parser = new Xoh_img_xoimg_parser();
public Html_atr Img_alt() {return img_alt;} private Html_atr img_alt;
public boolean Img_alt__diff__anch_title() {return !Bry_.Match(src, img_alt.Val_bgn(), img_alt.Val_end(), src, anch_title.Val_bgn(), anch_title.Val_end());}
public int Img_w() {return img_w;} private int img_w;
public int Img_h() {return img_h;} private int img_h;
public boolean Img_w__diff__file_w() {return img_w != img_src.File_w();}
public boolean Rel_nofollow_exists() {
if (anch_href.Site_exists()) {
if (rel_nofollow_exists == Bool_.__byte) {
Xow_domain_itm itm = Xow_domain_itm_.parse(Bry_.Mid(src, anch_href.Site_bgn(), anch_href.Site_end()));
rel_nofollow_exists = itm.Domain_type_id() == Xow_domain_tid_.Int__other ? Bool_.Y_byte : Bool_.N_byte;
}
return rel_nofollow_exists == Bool_.Y_byte;
}
else
return false;
} private byte rel_nofollow_exists;
private void Clear() {
this.rel_nofollow_exists = Bool_.__byte;
this.src_bgn = src_end = img_w = img_h = -1;
this.anch_title = this.img_alt = Html_atr.Noop;
}
public boolean Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_head) {
this.Clear();
this.src = src; Bry_err_wkr err_wkr = tag_rdr.Err_wkr();
this.src_bgn = anch_head.Src_bgn(); // <a
if (!anch_href.Parse(err_wkr, hctx, anch_head)) return false; // href='/wiki/File:A.png'
if (!anch_cls.Parse(err_wkr, src, anch_head)) return false; // class='image'
this.anch_title = anch_head.Atrs__get_by_or_empty(Html_atr_.Bry__title); // title='abc'
Html_atr xowa_title = anch_head.Atrs__get_by_or_empty(Bry__atr__xowa_title); // xowa_title='A.png'
if (xowa_title.Val_dat_exists()) anch_page.Val_(xowa_title.Val());
Html_tag img_tag = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__img); // <img
img_xoimg_parser.Parse(err_wkr, src, img_tag); // data-xoimg='...'
this.img_w = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__width, Xof_img_size.Size__neg1); // width='220'
this.img_h = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__height, Xof_img_size.Size__neg1); // height='110'
this.img_alt = img_tag.Atrs__get_by_or_empty(Html_atr_.Bry__alt); // alt='File:A.png'
img_cls.Parse(err_wkr, src, img_tag); // class='thumbborder'
if (!img_src.Parse(err_wkr, hctx.Wiki__domain_bry(), img_tag)) return false; // src='...'
if (anch_page.Val_is_empty()) {
anch_page.Val_(img_src.File_ttl_bry());
if (anch_page.Val_is_empty())
anch_page.Val_(anch_href.Ttl_page_db());
}
Html_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
this.src_end = anch_tail.Src_end();
return true;
}
public static final byte[]
Bry__cls__anch__image = Bry_.new_a7("image")
, Bry__cls__img__thumbimage = Bry_.new_a7("thumbimage")
, Bry__atr__xowa_title = Bry_.new_a7("xowa_title")
;
}

View File

@@ -16,57 +16,102 @@ 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.core.brys.args.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
public class Xoh_img_wtr extends gplx.core.brys.Bfr_arg_base {
private final Bfr_arg[] arg_ary;
private final Bfr_arg__indent indent = new Bfr_arg__indent();
private final Bfr_arg__html_atr
anch_href = new Bfr_arg__html_atr(Html_atr_.Bry__href)
, anch_rel = new Bfr_arg__html_atr(Html_atr_.Bry__rel)
, anch_cls = new Bfr_arg__html_atr(Html_atr_.Bry__class)
, anch_title = new Bfr_arg__html_atr(Html_atr_.Bry__title)
, anch_xowa_title = new Bfr_arg__html_atr(Xoh_img_parser.Bry__atr__xowa_title)
, img_id = new Bfr_arg__html_atr(Html_atr_.Bry__id)
, img_xoimg = new Bfr_arg__html_atr(Xoh_img_xoimg_parser.Bry__name)
, img_alt = new Bfr_arg__html_atr(Html_atr_.Bry__alt)
, img_src = new Bfr_arg__html_atr(Html_atr_.Bry__src)
, img_w = new Bfr_arg__html_atr(Html_atr_.Bry__width)
, img_h = new Bfr_arg__html_atr(Html_atr_.Bry__height)
, img_cls = new Bfr_arg__html_atr(Html_atr_.Bry__class)
;
private final Bfr_arg__id img_id_val = new Bfr_arg__id();
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.core.brys.args.*; import gplx.core.brys.fmtrs.*; import gplx.core.threads.poolables.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
import gplx.xowa.files.*;
public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
private final Bfr_arg_clearable[] arg_ary;
private final Bfr_arg__hatr_arg img_xoimg = new Bfr_arg__hatr_arg(Xoh_img_xoimg_data.Bry__name);
private final Bfr_arg__hatr_id img_id = Bfr_arg__hatr_id.New(Xoh_img_mgr.Bry__html_uid), vid_play_id = Bfr_arg__hatr_id.New("xowa_file_play_");
private final Bfr_arg__hatr_int img_w = new Bfr_arg__hatr_int(Gfh_atr_.Bry__width), img_h = new Bfr_arg__hatr_int(Gfh_atr_.Bry__height);
private final Bfr_arg__hatr_bry
anch_href = new Bfr_arg__hatr_bry(Gfh_atr_.Bry__href)
, anch_rel = new Bfr_arg__hatr_bry(Gfh_atr_.Bry__rel)
, anch_xowa_title = new Bfr_arg__hatr_bry(Xoh_img_data.Bry__atr__xowa_title)
, anch_cls = new Bfr_arg__hatr_bry(Gfh_atr_.Bry__class)
, anch_title = new Bfr_arg__hatr_bry(Gfh_atr_.Bry__title)
, img_alt = new Bfr_arg__hatr_bry(Gfh_atr_.Bry__alt)
, img_src = new Bfr_arg__hatr_bry(Gfh_atr_.Bry__src)
, img_cls = new Bfr_arg__hatr_bry(Gfh_atr_.Bry__class);
private boolean img_is_vid;
private byte[] xowa_root_dir;
public Xoh_img_wtr() {
arg_ary = new Bfr_arg[]
{ indent, anch_href, anch_rel, anch_cls, anch_title, anch_xowa_title
arg_ary = new Bfr_arg_clearable[]
{ anch_href, anch_rel, anch_cls, anch_title, anch_xowa_title
, img_id, img_xoimg, img_src, img_w, img_h, img_cls, img_alt
};
}
public Bfr_arg__html_atr Img_alt() {return img_alt;}
public Xoh_img_wtr Indent_(int v) {indent.Set(v); return this;}
public Xoh_img_wtr Anch_href_(Bfr_arg v) {anch_href.Set_by_arg(v); return this;}
public Xoh_img_wtr Anch_rel_nofollow_() {anch_rel.Set_by_bry(gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_dict_.Html__rel__nofollow); return this;}
public Xoh_img_wtr Anch_cls_(Bfr_arg v) {anch_cls.Set_by_arg(v); return this;}
public Xoh_img_wtr Anch_title_(Bfr_arg v) {anch_title.Set_by_arg(v); return this;}
public Xoh_img_wtr Anch_xowa_title_(byte[] v) {anch_xowa_title.Set_by_bry(v); return this;}
public Xoh_img_wtr Img_id_(byte[] prefix, int uid) {img_id.Set_by_arg(img_id_val.Set(prefix, uid)); return this;}
public Xoh_img_wtr Img_w_(int v) {img_w.Set_by_int(v); return this;}
public Xoh_img_wtr Img_h_(int v) {img_h.Set_by_int(v); return this;}
public Xoh_img_wtr Img_xoimg_(Bfr_arg v) {img_xoimg.Set_by_arg(v); return this;}
public Xoh_img_wtr Img_cls_(Bfr_arg v) {img_cls.Set_by_arg(v); return this;}
public Xoh_img_wtr Img_src_(Bfr_arg v) {img_src.Set_by_arg(v); return this;}
public Xoh_img_wtr Img_src_empty_() {img_src.Set_by_bry(Bry_.Empty); return this;}
public Xoh_img_wtr Img_alt_(Bfr_arg v) {img_alt.Set_by_arg(v); return this;}
public Xof_fsdb_itm Fsdb_itm() {return fsdb_itm;} private Xof_fsdb_itm fsdb_itm;
public Xoh_img_wtr Anch_cls_(byte[] v) {anch_cls.Set_by_bry(v); return this;}
public Xoh_img_wtr Img_id_(int uid) {img_id.Set(uid); return this;}
public Xoh_img_wtr Clear() {
for (Bfr_arg arg : arg_ary)
for (Bfr_arg_clearable arg : arg_ary)
arg.Bfr_arg__clear();
vid_play_id.Bfr_arg__clear();
img_is_vid = false;
return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, (Object[])arg_ary);
public void Init_by_parse(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_img_data data) {
Init_by_decode(hpg, hctx, src, data);
this.Bfr_arg__add(bfr);
}
private static final Bry_fmtr fmtr = Bry_fmtr.new_
( "~{indent}<a~{anch_href}~{anch_rel}~{anch_cls}~{anch_title}~{anch_xowa_title}><img~{img_id}~{img_xoimg}~{img_src}~{img_w}~{img_h}~{img_cls}~{img_alt}></a>"
, "indent", "anch_href", "anch_rel", "anch_cls", "anch_title", "anch_xowa_title", "img_id", "img_xoimg", "img_src", "img_w", "img_h", "img_cls", "img_alt");
public boolean Init_by_decode(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_data_itm data_itm) {
Xoh_img_data data = (Xoh_img_data)data_itm;
this.Clear();
this.img_is_vid = data.Img_is_vid();
this.fsdb_itm = hpg.Img_mgr().Make_img();
byte[] file_ttl_bry = data.Img_src().File_ttl_bry();
byte[] lnki_ttl = Xoa_ttl.Replace_spaces(Gfo_url_encoder_.Href_quotes.Decode(file_ttl_bry)); // NOTE: must decode for fsdb.lnki_ttl as well as xowa_title; EX: A%C3%A9b -> A<>b
if (data.Img_xoimg().Val_dat_exists()) {
Xoh_img_xoimg_data img_xoimg = data.Img_xoimg();
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), lnki_ttl, gplx.xowa.parsers.lnkis.Xop_lnki_type.To_flag(img_xoimg.Lnki_type()), img_xoimg.Lnki_upright(), img_xoimg.Lnki_w(), img_xoimg.Lnki_h(), img_xoimg.Lnki_time(), img_xoimg.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
hctx.File__mgr().Check_cache(fsdb_itm);
this.img_xoimg.Set_by_arg(img_xoimg);
img_w.Set_by_int(0);
img_h.Set_by_int(0);
this.img_src.Set_by_bry(Bry_.Empty);
}
else if (data.Img_w() != -1) {
img_w.Set_by_int(data.Img_w());
img_h.Set_by_int(data.Img_h());
this.img_src.Set_by_arg(data.Img_src());
}
if (data.Anch_rel_nofollow_exists()) anch_rel.Set_by_bry(gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_dict_.Html__rel__nofollow);
if (!hctx.Mode_is_diff()) {
this.Img_id_(fsdb_itm.Html_uid());
vid_play_id.Set(fsdb_itm.Html_uid());
}
anch_href.Set_by_mid(data.Anch_href().Rng_src(), data.Anch_href().Rng_bgn(), data.Anch_href().Rng_end());
anch_cls.Set_by_arg(data.Anch_cls());
anch_title.Set_by_mid_or_null(src, data.Anch_title_bgn(), data.Anch_title_end());
anch_xowa_title.Set_by_bry(file_ttl_bry);
xowa_root_dir = hctx.Fsys__root();
img_alt.Set_by_mid_or_empty(src, data.Img_alt_bgn(), data.Img_alt_end());
img_cls.Set_by_arg(data.Img_cls());
return true;
}
public void Init_by_gly(Bfr_arg_clearable href, byte[] xowa_title, Bfr_arg_clearable xoimg) {
anch_href.Set_by_arg(href);
anch_xowa_title.Set_by_bry(xowa_title);
img_xoimg.Set_by_arg(xoimg);
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (img_is_vid) bfr.Add(Vid__bry__bgn);
img_fmtr.Bld_bfr_many(bfr, (Object[])arg_ary);
if (img_is_vid)
vid_fmtr.Bld_bfr_many(bfr, vid_play_id, anch_xowa_title, xowa_root_dir, 218, 220); // TODO: hardcode widths; need to update via js from fsdb
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_wtr rv = new Xoh_img_wtr(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
private static final byte[] Vid__bry__bgn = Bry_.new_a7("<div class=\"xowa_media_div\">\n<div>");
private static final Bry_fmtr
img_fmtr = Bry_fmtr.new_
( "<a~{anch_href}~{anch_rel}~{anch_cls}~{anch_title}~{anch_xowa_title}><img~{img_id}~{img_xoimg}~{img_src}~{img_w}~{img_h}~{img_cls}~{img_alt}></a>"
, "anch_href", "anch_rel", "anch_cls", "anch_title", "anch_xowa_title", "img_id", "img_xoimg", "img_src", "img_w", "img_h", "img_cls", "img_alt")
, vid_fmtr = Bry_fmtr.new_
( "</div>\n<div><a~{vid_play_id} href=\"\"~{xowa_title} class=\"xowa_anchor_button\" style=\"width:218px;max-width:220px;\"><img src=\"\" width=\"22\" height=\"22\" alt=\"Play sound\"></a></div>\n</div>"
, "vid_play_id", "xowa_title", "xowa_root_dir", "width_neg_2", "width") // NOTE: default to href='file:///'; will be filled in dynamically
;
}

View File

@@ -30,7 +30,7 @@ public class Xoh_anch_cls_ {
Bry__image = Bry_.new_a7(Str__image)
;
private static final byte[]
Html__image = Bry_.Add(Html_bldr_.Bry__cls__nth, Bry__image)
Html__image = Bry_.Add(Gfh_bldr_.Bry__cls__nth, Bry__image)
;
public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs()
.Add_bry_byte(Bry__image , Tid__image)

View File

@@ -17,22 +17,26 @@ 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 {
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
public class Xoh_anch_cls_data implements Bfr_arg_clearable {
private final Bry_rdr rdr = new Bry_rdr();
public byte Tid() {return tid;} private byte tid;
public Html_atr Atr() {return atr;} private Html_atr atr;
public boolean Parse(Bry_err_wkr err_wkr, byte[] src, Html_tag tag) {
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='image'
public void Clear() {
tid = Xoh_anch_cls_.Tid__none;
}
public boolean Parse(Bry_err_wkr err_wkr, byte[] src, Gfh_tag tag) {
Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__class); // EX: class='image'
int src_bgn = atr.Val_bgn(); int src_end = atr.Val_end();
if (src_bgn == -1) {
tid = Xoh_anch_cls_.Tid__none;
return false;
}
else {
rdr.Init_by_wkr(err_wkr, "anch.cls", src_bgn, src_end);
this.tid = rdr.Chk_or(Xoh_anch_cls_.Trie, Byte_ascii.Max_7_bit);
return tid != Byte_ascii.Max_7_bit;
}
if (src_bgn == -1) return false;
rdr.Init_by_wkr(err_wkr, "anch.cls", src_bgn, src_end);
this.tid = rdr.Chk_or(Xoh_anch_cls_.Trie, Byte_ascii.Max_7_bit);
return tid != Byte_ascii.Max_7_bit;
}
public void Init_by_decode(int tid) {this.tid = (byte)tid;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(Xoh_anch_cls_.To_val(tid));
}
}

View File

@@ -19,9 +19,10 @@ package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*;
public class Xoh_img_cls_ {
public static final byte // SERIALIZED
Tid__none = 0 // EX: [[File:A.png]] -> "<img>"
, Tid__thumbimage = 1 // EX: [[File:A.png|thumb]] -> "<img class='thumbimage'>"
, Tid__thumbborder = 2 // EX: [[File:A.png|border]] -> "<img class='thumbborder'>"
Tid__none = 0 // EX: [[File:A.png]] -> "<img>"
, Tid__thumbimage = 1 // EX: [[File:A.png|thumb]] -> "<img class='thumbimage'>"
, Tid__thumbborder = 2 // EX: [[File:A.png|border]] -> "<img class='thumbborder'>"
, Tid__manual = 3 // EX: [[File:A.png|class=x]] -> "<img class='x'>"
;
public static final String
Str__thumbimage = "thumbimage"
@@ -30,7 +31,7 @@ public class Xoh_img_cls_ {
public static final byte[]
Bry__none = Bry_.Empty
;
private static final byte[]
public static final byte[]
Bry__thumbimage = Bry_.new_a7(Str__thumbimage)
, Bry__thumbborder = Bry_.new_a7(Str__thumbborder)
;

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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.docs.*;
public class Xoh_img_cls_data implements Bfr_arg_clearable {
private byte[] src;
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 Clear() {
cls_tid = Xoh_img_cls_.Tid__none; other_bgn = other_end = -1;
src = null;
}
public void Init_by_decode(byte[] src, int cls_tid, int other_bgn, int other_end) {
this.src = src;
this.cls_tid = (byte)cls_tid; this.other_bgn = other_bgn; this.other_end = other_end;
}
public void Init_by_parse(Bry_err_wkr err_wkr, byte[] src, Gfh_tag tag) {
this.Clear();
Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__class); // EX: class='thumbborder'
int src_bgn = atr.Val_bgn();
if (src_bgn == -1) { // class does not exist; defaults to none and exit;
cls_tid = Xoh_img_cls_.Tid__none;
return;
}
int src_end = atr.Val_end();
this.cls_tid = Xoh_img_cls_.Trie.Match_byte_or(src, src_bgn, src_end, Xoh_img_cls_.Tid__manual);
int pos = Xoh_img_cls_.Trie.Match_pos();
if (pos < src_end && src[pos] == Byte_ascii.Space)
++pos;
if (cls_tid == Xoh_img_cls_.Tid__manual || pos < src_end) {
this.other_bgn = pos;
this.other_end = src_end;
}
}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return cls_tid == Xoh_img_cls_.Tid__none && other_end <= other_bgn;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
byte[] cls = null;
switch (cls_tid) {
case Xoh_img_cls_.Tid__thumbimage: cls = Xoh_img_cls_.Bry__thumbimage; break;
case Xoh_img_cls_.Tid__thumbborder: cls = Xoh_img_cls_.Bry__thumbborder; break;
}
if (cls != null)
bfr.Add(cls);
if (other_end > other_bgn) {
if (cls != null) bfr.Add_byte_space();
bfr.Add_mid(src, other_bgn, other_end);
}
}
}

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.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 Html_atr Atr() {return atr;} private Html_atr atr;
public void Parse(Bry_err_wkr err_wkr, byte[] src, Html_tag tag) {
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='thumbborder'
Parse(err_wkr, src, atr.Val_bgn(), atr.Val_end());
}
private void Parse(Bry_err_wkr err_wkr, 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_wkr(err_wkr, "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

@@ -17,47 +17,45 @@ 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.langs.htmls.*; import gplx.langs.htmls.docs.*;
import gplx.xowa.wikis.domains.*;
public class Xoh_img_src_parser implements Xoh_itm_parser {
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash); private byte[] src;
public class Xoh_img_src_data implements Bfr_arg_clearable, Xoh_itm_parser {
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash);
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
public 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[] Src_bry() {return src_bry;} private byte[] src_bry;
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
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 byte[] File_ttl_bry() {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 Html_atr Atr() {return atr;} private Html_atr atr;
private void Clear() {
val_bgn = val_end = repo_bgn = repo_end = file_ttl_bgn = file_ttl_end = file_w = file_time = file_page = -1;
public void Clear() {
src_bry = null;
src_bgn = src_end = repo_bgn = repo_end = file_ttl_bgn = file_ttl_end = file_w = file_time = file_page = -1;
repo_is_commons = file_is_orig = false;
file_ttl_bry = null;
atr = null;
}
public boolean Parse(Bry_err_wkr err_wkr, byte[] domain_bry, Html_tag tag) {
public boolean Parse(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, byte[] domain_bry, Gfh_tag tag) {
this.Clear();
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__src);
return Parse(err_wkr, domain_bry, atr.Val_bgn(), atr.Val_end());
Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__src);
return Parse(err_wkr, hctx, domain_bry, atr.Val_bgn(), atr.Val_end());
}
public boolean Parse(Bry_err_wkr err_wkr, byte[] domain_bry, int val_bgn, int val_end) { // EX: src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png"
public boolean Parse(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, byte[] domain_bry, int src_bgn, int src_end) { // EX: src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png"
this.Clear();
this.src = err_wkr.Src();
this.val_bgn = val_bgn; this.val_end = val_end;
if (val_end == val_bgn) return true; // empty src; just return true;
this.src_bry = err_wkr.Src();
this.src_bgn = src_bgn; this.src_end = src_end;
if (src_end == src_bgn) return true; // empty src; just return true;
file_w = file_time = file_page = -1;
rdr.Init_by_wkr(err_wkr, "img.src.xowa", val_bgn, val_end);
rdr.Fail_throws_err_(Bool_.N);
rdr.Init_by_wkr(err_wkr, "img.src.xowa", src_bgn, src_end).Fail_throws_err_(Bool_.N);
repo_bgn = rdr.Find_fwd_rr(Bry__file); // skip past /file/; EX: "file:///J:/xowa/file/commons.wikimedia.org/"
if (repo_bgn == -1) return false;
rdr.Fail_throws_err_(Bool_.Y);
@@ -80,13 +78,21 @@ public class Xoh_img_src_parser implements Xoh_itm_parser {
else if (rdr.Is(Byte_ascii.Dash))
file_page = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px-5.png"
}
file_ttl_bry = Bry_.Mid(src_bry, file_ttl_bgn, file_ttl_end);
return true;
}
public void Init_by_decode(byte[] file_ttl_bry, byte[] src) {
this.file_ttl_bry = file_ttl_bry;
this.src_bry = src; this.src_bgn = 0; this.src_end = src.length;
}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return src_bry == null;}
public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_mid(src_bry, src_bgn, src_end);}
private int Skip_md5() {
byte[] src = rdr.Src();
int pos = rdr.Pos();
while (true) {
if ( pos < val_end // no more slashes; shouldn't happen; EX: "7/0/"
if ( pos < src_end // no more slashes; shouldn't happen; EX: "7/0/"
&& src[pos + 1] == Byte_ascii.Slash) { // pos is slash; EX: "7/0/"
pos += 2;
continue;

View File

@@ -18,8 +18,8 @@ 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();
public class Xoh_img_src_data_tst {
private final Xoh_img_src_data_fxt fxt = new Xoh_img_src_data_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);
@@ -36,7 +36,7 @@ public class Xoh_img_src_parser_tst {
// 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 { private final Xoh_img_src_parser parser = new Xoh_img_src_parser();
class Xoh_img_src_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_img_src_data parser = new Xoh_img_src_data();
@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);
@@ -48,6 +48,7 @@ class Xoh_img_src_parser_fxt extends Xoh_itm_parser_fxt { private final Xoh_img
Tfds.Eq_int(expd_page, parser.File_page());
}
@Override public void Exec_parse_hook(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end) {
parser.Parse(err_wkr, Xow_domain_itm_.Bry__enwiki, src_bgn, src_end);
// Xoh_hdoc_ctx hctx
parser.Parse(err_wkr, new Xoh_hdoc_ctx(), Xow_domain_itm_.Bry__enwiki, src_bgn, src_end);
}
}

View File

@@ -17,12 +17,12 @@ 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 implements Bfr_arg {
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
public class Xoh_img_xoimg_data implements Bfr_arg_clearable {
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Pipe);
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_dat_exists() {return val_end > val_bgn;}
public boolean Val_dat_exists() {return val_dat_exists;} private boolean val_dat_exists;
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;
@@ -31,6 +31,7 @@ public class Xoh_img_xoimg_parser implements Bfr_arg {
public int Lnki_page() {return lnki_page;} private int lnki_page;
public void Clear() {
val_bgn = val_end = -1;
val_dat_exists = false;
}
public void Set(byte tid, int w, int h, double upright, double time, int page) {
this.lnki_type = tid;
@@ -39,9 +40,10 @@ public class Xoh_img_xoimg_parser implements Bfr_arg {
this.lnki_upright = upright;
this.lnki_time = time;
this.lnki_page = page;
this.val_dat_exists = true;
}
public void Parse(Bry_err_wkr err_wkr, byte[] src, Html_tag tag) {
Html_atr atr = tag.Atrs__get_by_or_empty(Bry__name);
public void Parse(Bry_err_wkr err_wkr, byte[] src, Gfh_tag tag) {
Gfh_atr atr = tag.Atrs__get_by_or_empty(Bry__name);
Parse(err_wkr, src, atr.Val_bgn(), atr.Val_end());
}
public void Parse(Bry_err_wkr err_wkr, byte[] src, int src_bgn, int src_end) {
@@ -57,10 +59,11 @@ public class Xoh_img_xoimg_parser implements Bfr_arg {
this.lnki_upright = rdr.Read_double_to();
this.lnki_time = rdr.Read_double_to();
this.lnki_page = rdr.Read_int_to();
this.val_dat_exists = true;
}
}
public void Bfr_arg__clear() {}
public boolean Bfr_arg__exists() {return true;}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add_int_variable(lnki_type).Add_byte_pipe();
bfr.Add_int_variable(lnki_w).Add_byte_pipe();

View File

@@ -20,7 +20,7 @@ import gplx.core.brys.*;
import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.files.*;
public class Xoh_img_xoimg_hzip {
public void Encode(Bry_bfr bfr, Xoh_stat_itm stat_itm, byte[] src, Xoh_img_xoimg_parser arg) {
public void Encode(Bry_bfr bfr, Xoh_stat_itm stat_itm, byte[] src, Xoh_img_xoimg_data arg) {
boolean page_exists = arg.Lnki_page() != Xof_lnki_page.Null;
boolean time_exists = arg.Lnki_time() != Xof_lnki_time.Null;
boolean upright_exists = arg.Lnki_upright() != Xof_img_size.Upright_null;
@@ -39,8 +39,8 @@ public class Xoh_img_xoimg_hzip {
if (time_exists) bfr.Add_double(arg.Lnki_time()).Add_byte(Xoh_hzip_dict_.Escape);
if (page_exists) Xoh_hzip_int_.Encode(2, bfr, arg.Lnki_page());
}
public void Decode(Bry_bfr bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, Xoh_img_xoimg_parser arg) {
int flag = rdr.Read_int_by_base85(1);
public void Decode(Bry_bfr bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, Xoh_img_xoimg_data arg) {
int flag = rdr.Read_hzip_int(1);
flag_bldr.Decode(flag);
boolean page_exists = flag_bldr.Get_as_bool(Flag__page_exists);
boolean time_exists = flag_bldr.Get_as_bool(Flag__time_exists);
@@ -48,11 +48,11 @@ public class Xoh_img_xoimg_hzip {
boolean height_exists = flag_bldr.Get_as_bool(Flag__height_exists);
boolean width_exists = flag_bldr.Get_as_bool(Flag__width_exists);
byte tid = flag_bldr.Get_as_byte(Flag__lnki_type);
int w = width_exists ? rdr.Read_int_by_base85(2) : Xof_img_size.Size__neg1;
int h = height_exists ? rdr.Read_int_by_base85(2) : Xof_img_size.Size__neg1;
int w = width_exists ? rdr.Read_hzip_int(2) : Xof_img_size.Size__neg1;
int h = height_exists ? rdr.Read_hzip_int(2) : Xof_img_size.Size__neg1;
double upright = upright_exists ? rdr.Read_double_to(Xoh_hzip_dict_.Escape) : Xof_img_size.Upright_null;
double time = time_exists ? rdr.Read_double_to(Xoh_hzip_dict_.Escape) : Xof_lnki_time.Null;
int page = page_exists ? rdr.Read_int_by_base85(2) : Xof_lnki_page.Null;
int page = page_exists ? rdr.Read_hzip_int(2) : Xof_lnki_page.Null;
arg.Set(tid, w, h, upright, time, page);
}
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1 , 1, 1, 1, 3);

View File

@@ -16,33 +16,37 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*;
public class Xoh_lnke_parser {
private final Bry_rdr rdr = new Bry_rdr();
import gplx.core.brys.*; import gplx.core.threads.poolables.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_lnke_data implements Xoh_data_itm {
public int Tid() {return Xoh_hzip_dict_.Tid__lnke;}
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public byte Lnke_tid() {return lnke_tid;} private byte lnke_tid;
public boolean Auto_exists() {return auto_id != -1;}
public int Auto_id() {return auto_id;} private int auto_id;
public int Href_bgn() {return href_bgn;} private int href_bgn;
public int Href_end() {return href_end;} private int href_end;
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
public int Capt_end() {return capt_end;} private int capt_end;
public boolean Capt_exists() {return capt_exists;} private boolean capt_exists;
private void Clear() {
lnke_tid = Byte_ascii.Max_7_bit;
public void Clear() {
capt_exists = false;
lnke_tid = Byte_ascii.Max_7_bit;
src_bgn = src_end = href_bgn = href_end = capt_bgn = capt_end = auto_id = -1;
}
public boolean Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Html_tag_rdr tag_rdr, byte[] src, Html_tag anch_head) {
this.Clear();
public void Init_by_decode(byte lnke_tid, int auto_id, int href_bgn, int href_end, int capt_bgn, int capt_end, boolean capt_exists) {
this.lnke_tid = lnke_tid; this.auto_id = auto_id; this.href_bgn = href_bgn; this.href_end = href_end;
this.capt_bgn = capt_bgn; this.capt_end = capt_end; this.capt_exists = capt_exists;
}
public boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag anch_head, Gfh_tag unused) {
this.src_bgn = anch_head.Src_bgn();
rdr.Init_by_sect("lnke", src_bgn, src_bgn);
Html_atr href_atr = anch_head.Atrs__get_by_or_fail(Html_atr_.Bry__href); // get href; "EX: href='http://a.org'"
Gfh_atr href_atr = anch_head.Atrs__get_by_or_fail(Gfh_atr_.Bry__href); // get href; "EX: href='http://a.org'"
this.href_bgn = href_atr.Val_bgn(); this.href_end = href_atr.Val_end();
this.lnke_tid = anch_head.Atrs__cls_find_or_fail(Xoh_lnke_dict_.Hash); // get type by class; EX: "class='external free'"
this.capt_bgn = anch_head.Src_end();
Html_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // find '</a>'
Gfh_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__a); // find '</a>'
this.capt_end = anch_tail.Src_bgn();
switch (lnke_tid) {
case Xoh_lnke_dict_.Type__free:
@@ -66,7 +70,8 @@ public class Xoh_lnke_parser {
break;
}
this.src_end = anch_tail.Src_end();
hdoc_wkr.On_lnke(this);
return true;
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_lnke_data rv = new Xoh_lnke_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
}

View File

@@ -25,7 +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
bfr.Add(Xoh_consts.A_bgn);
bfr.Add(Gfh_bldr_.Bry__a_lhs_w_href);
if (Write_href(bfr, hctx, 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);
@@ -34,7 +34,7 @@ public class Xoh_lnke_html {
if (!hctx.Mode_is_alt()) {
if (proto_is_xowa) // add <img />
bfr.Add(Xoh_consts.Img_bgn).Add(html_wtr.Html_mgr().Img_xowa_protocol()).Add(Xoh_consts.__inline_quote);
bfr.Add(Xoh_consts.A_end);
bfr.Add(Gfh_bldr_.Bry__a_rhs);
}
}
public boolean Write_href(Bry_bfr bfr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke, int href_bgn, int href_end, boolean proto_is_xowa) {

View File

@@ -19,13 +19,14 @@ package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; impo
import gplx.core.brys.*; import gplx.core.threads.poolables.*; import gplx.xowa.wikis.ttls.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*;
public class Xoh_lnke_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
public int Tid() {return Xoh_hzip_dict_.Tid__lnke;}
public String Key() {return Xoh_hzip_dict_.Key__lnke;}
public byte[] Hook() {return hook;} private byte[] hook;
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_lnke_parser data = (Xoh_lnke_parser)data_obj;
boolean auto_exists = flag_bldr.Set_as_bool(Flag__auto_exists , data.Auto_id() != -1);
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_lnke_data data = (Xoh_lnke_data)data_obj;
boolean auto_exists = flag_bldr.Set_as_bool(Flag__auto_exists , data.Auto_exists());
boolean capt_exists = flag_bldr.Set_as_bool(Flag__capt_exists , data.Capt_exists());
byte lnke_tid = flag_bldr.Set_as_byte(Flag__lnke_tid , data.Lnke_tid());
byte lnke_tid = flag_bldr.Set_as_byte(Flag__lnke_tid , data.Lnke_tid());
bfr.Add(hook);
bfr.Add_hzip_int(1, flag_bldr.Encode()); // add flag
@@ -36,27 +37,19 @@ public class Xoh_lnke_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
hctx.Hzip__stat().Lnke_add(lnke_tid);
return this;
}
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
int flag = rdr.Read_int_by_base85(1); flag_bldr.Decode(flag);
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
int flag = rdr.Read_hzip_int(1); flag_bldr.Decode(flag);
boolean auto_exists = flag_bldr.Get_as_bool(Flag__auto_exists);
boolean capt_exists = flag_bldr.Get_as_bool(Flag__capt_exists);
byte lnke_tid = flag_bldr.Get_as_byte(Flag__lnke_tid);
byte lnke_tid = flag_bldr.Get_as_byte(Flag__lnke_tid);
int href_bgn = rdr.Pos(); int href_end = rdr.Find_fwd_lr();
int auto_id = -1, capt_bgn = -1, capt_end = -1;
if (auto_exists) auto_id = rdr.Read_int_by_base85(1);
if (auto_exists) auto_id = rdr.Read_hzip_int(1);
if (capt_exists) {capt_bgn = rdr.Pos(); capt_end = rdr.Find_fwd_lr();}
int rv = rdr.Pos();
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
bfr.Add_mid(src, href_bgn, href_end);
bfr.Add(Xoh_lnke_dict_.Html__atr__0).Add(Xoh_lnke_dict_.To_html_class(lnke_tid)).Add(Xoh_lnke_dict_.Html__rhs_end);
if (auto_exists) bfr.Add_byte(Byte_ascii.Brack_bgn).Add_int_variable(auto_id).Add_byte(Byte_ascii.Brack_end);
else if (capt_exists) bfr.Add_mid(src, capt_bgn, capt_end);
else bfr.Add_mid(src, href_bgn, href_end);
bfr.Add(Html_bldr_.Bry__a_rhs);
return rv;
Xoh_lnke_data data = (Xoh_lnke_data)data_itm;
data.Init_by_decode(lnke_tid, auto_id, href_bgn, href_end, capt_bgn, capt_end, capt_exists);
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_lnke_hzip rv = new Xoh_lnke_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}

View File

@@ -16,33 +16,35 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.core.brys.args.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
import gplx.xowa.htmls.core.wkrs.bfr_args.*;
public class Xoh_lnke_wtr extends gplx.core.brys.Bfr_arg_base {
private final Bfr_arg[] arg_ary;
private final Bfr_arg__html_atr
anch_href = new Bfr_arg__html_atr(Html_atr_.Bry__href)
, anch_rel = new Bfr_arg__html_atr(Html_atr_.Bry__rel)
, anch_cls = new Bfr_arg__html_atr(Html_atr_.Bry__class)
;
private final Bfr_arg__wrapper anch_capt = new Bfr_arg__wrapper();
public Xoh_lnke_wtr() {
arg_ary = new Bfr_arg[] {anch_href, anch_rel, anch_cls, anch_capt};
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*; import gplx.core.threads.poolables.*; import gplx.core.brys.args.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*;
import gplx.xowa.htmls.core.hzips.*;
public class Xoh_lnke_wtr implements gplx.core.brys.Bfr_arg, Xoh_wtr_itm {
private final Bfr_arg__bry anch_href = Bfr_arg__bry.New_empty(), anch_cls = Bfr_arg__bry.New_empty(), anch_content = Bfr_arg__bry.New_empty();
public boolean Init_by_decode(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_data_itm data_itm) {
Bfr_arg_.Clear(anch_href, anch_cls,anch_content);
Xoh_lnke_data data = (Xoh_lnke_data)data_itm;
anch_href.Set_by_mid(src, data.Href_bgn(), data.Href_end());
anch_cls.Set_by_val(Xoh_lnke_dict_.To_html_class(data.Lnke_tid()));
if (data.Auto_exists()) anch_content.Set_by_arg(Xoh_lnke_wtr_arg__autonum.Instance.Set_by_auto_id(data.Auto_id()));
else if (data.Capt_exists()) anch_content.Set_by_mid(src, data.Capt_bgn(), data.Capt_end());
else anch_content.Set_by_mid(src, data.Href_bgn(), data.Href_end());
return true;
}
public Xoh_lnke_wtr Anch_href_(byte[] src, int bgn, int end) {anch_href.Set_by_mid(src, bgn, end); return this;}
public Xoh_lnke_wtr Anch_rel_y_() {anch_rel.Set_by_bry(Xoh_lnke_dict_.Html__rel__nofollow); return this;}
public Xoh_lnke_wtr Anch_cls_(byte[]... ary) {anch_cls.Set_by_ary(ary); return this;}
public Xoh_lnke_wtr Anch_capt_(Bfr_arg v) {anch_capt.Set(v); return this;}
public Xoh_lnke_wtr Clear() {
for (Bfr_arg arg : arg_ary)
arg.Bfr_arg__clear();
return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, (Object[])arg_ary);
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, anch_href, anch_cls, anch_content);
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_lnke_wtr rv = new Xoh_lnke_wtr(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
private static final Bry_fmtr fmtr = Bry_fmtr.new_
( "<a~{anch_href}~{anch_rel}~{anch_cls}>~{anch_capt}</a>"
, "anch_href", "anch_rel", "anch_cls", "anch_capt");
( "<a href=\"~{href}\" rel=\"nofollow\" class=\"external ~{cls}\">~{content}</a>"
, "href", "cls", "content");
}
class Xoh_lnke_wtr_arg__autonum implements Bfr_arg {
private int auto_id;
public Bfr_arg Set_by_auto_id(int auto_id) {this.auto_id = auto_id; return this;}
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_int_variable(auto_id).Add_byte(Byte_ascii.Brack_end);
}
public static final Xoh_lnke_wtr_arg__autonum Instance = new Xoh_lnke_wtr_arg__autonum(); Xoh_lnke_wtr_arg__autonum() {}
}

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.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.core.brys.*; import gplx.core.btries.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.hrefs.*;import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*;
public class Xoh_lnki_parser {
public class Xoh_lnki_data {
private byte[] src;
private int href_ns_id; private byte[] href_ns_name; private int href_ns_name_len;
private byte[] capt_src; private int capt_bgn, capt_end;
@@ -41,31 +41,36 @@ public class Xoh_lnki_parser {
public int Title_tid() {return title_tid;} private int title_tid;
public int Title_bgn() {return title_bgn;} private int title_bgn;
public int Title_end() {return title_end;} private int title_end;
public Xoh_anch_href_itm Href_itm() {return href_itm;} private final Xoh_anch_href_itm href_itm = new Xoh_anch_href_itm();
public boolean Tid_is_ctg_main() {return tid_is_ctg_main;} private boolean tid_is_ctg_main;
public boolean Tid_is_ctg_tree() {return tid_is_ctg_tree;} private boolean tid_is_ctg_tree;
public boolean Tid_is_ctg_xnav() {return tid_is_ctg_xnav;} private boolean tid_is_ctg_xnav;
public Xoh_anch_href_data Href_itm() {return href_itm;} private final Xoh_anch_href_data href_itm = new Xoh_anch_href_data();
public Xoh_anch_capt_itm Capt_itm() {return capt_itm;} private final Xoh_anch_capt_itm capt_itm = new Xoh_anch_capt_itm();
private void Init(byte[] src) {
this.src = href_src = capt_src = src;
capt_has_ns = title_missing_ns = false;
capt_has_ns = title_missing_ns = tid_is_ctg_main = tid_is_ctg_tree = tid_is_ctg_xnav = false;
href_ns_id = Xow_ns_.Tid__main; href_ns_name = null; href_ns_name_len = 0;
href_bgn = href_end = capt_bgn = capt_end = title_bgn = title_end = -1;
title_tid = Title__href;
href_itm.Clear();
}
public boolean Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Html_tag_rdr tag_rdr, byte[] src, Html_tag anch_head) {
public boolean Parse1(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag anch_head) {
Init(src);
this.src_bgn = anch_head.Src_bgn();
rdr.Init_by_wkr(tag_rdr.Err_wkr(), "lnki", src_bgn, src.length);
Html_atr title_atr = anch_head.Atrs__get_by_or_empty(Html_atr_.Bry__title);
Gfh_atr title_atr = anch_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__title);
Parse_href(hctx, anch_head);
Parse_cls(anch_head);
Parse_capt(tag_rdr, anch_head);
Parse_title(title_atr);
hdoc_wkr.On_lnki(this);
return true;
}
private void Parse_href(Xoh_hdoc_ctx hctx, Html_tag anch_head) {
href_itm.Parse(rdr.Err_wkr(), hctx, anch_head);
private void Parse_href(Xoh_hdoc_ctx hctx, Gfh_tag anch_head) {
href_itm.Parse(rdr.Err_wkr(), hctx, src, anch_head);
this.href_bgn = href_itm.Ttl_bgn(); this.href_end = href_itm.Ttl_end();
switch (href_itm.Tid()) {
case Xoh_anch_href_itm.Tid__wiki: case Xoh_anch_href_itm.Tid__site:
case Xoh_anch_href_data.Tid__wiki: case Xoh_anch_href_data.Tid__site:
this.href_ns_id = href_itm.Ttl_ns_id();
this.href_src = href_itm.Ttl_full_txt();
this.href_bgn = 0;
@@ -78,9 +83,18 @@ public class Xoh_lnki_parser {
break;
}
}
private void Parse_capt(Html_tag_rdr tag_rdr, Html_tag anch_head) {
private void Parse_cls(Gfh_tag anch_head) {
byte[] cls_bry = anch_head.Atrs__get_as_bry(Gfh_atr_.Bry__class);
byte cls_tid = Cls__trie.Match_byte_or(cls_bry, 0, cls_bry.length, Byte_.Max_value_127);
switch (cls_tid) {
case Cls_tid__main: this.tid_is_ctg_main = true; break;
case Cls_tid__tree: this.tid_is_ctg_tree = true; break;
case Cls_tid__xnav: this.tid_is_ctg_xnav = true; break;
}
}
private void Parse_capt(Gfh_tag_rdr tag_rdr, Gfh_tag anch_head) {
this.capt_bgn = anch_head.Src_end(); // capt starts after <a>
Html_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
Gfh_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Gfh_tag_.Id__a); // </a>
this.capt_end = anch_tail.Src_bgn(); // get capt between "<a>" and "</a>
this.src_end = anch_tail.Src_end();
// skip ns in href / capt
@@ -93,7 +107,7 @@ public class Xoh_lnki_parser {
}
}
// get text splits
this.text_tid = href_itm.Tid() == Xoh_anch_href_itm.Tid__anch
this.text_tid = href_itm.Tid() == Xoh_anch_href_data.Tid__anch
? Xoh_anch_capt_itm.Tid__diff
: capt_itm.Parse(rdr, capt_has_ns, href_src, href_bgn, href_end, src, capt_bgn, capt_end);
int split_pos = capt_itm.Split_pos();
@@ -115,7 +129,7 @@ public class Xoh_lnki_parser {
break;
}
}
private void Parse_title(Html_atr title_atr) {
private void Parse_title(Gfh_atr title_atr) {
// Tfds.Dbg(Bry_.Mid(href_src, href_bgn, href_end), Bry_.Mid(src, capt_bgn, capt_end), Bry_.Mid(src, title_bgn, title_end));
title_bgn = title_atr.Val_bgn(); title_end = title_atr.Val_end();
if (href_ns_name != null) { // ns_name exists
@@ -144,4 +158,11 @@ public class Xoh_lnki_parser {
, Title__diff = 2
, Title__missing = 3
;
public static final byte[] Cls_bry__main = Bry_.new_a7("internal"), Cls_bry__xnav = Bry_.new_a7("xowa_nav");
private static final byte Cls_tid__main = 0, Cls_tid__tree = 1, Cls_tid__xnav = 2;
private static final Btrie_slim_mgr Cls__trie = Btrie_slim_mgr.cs()
.Add_bry_byte(Cls_bry__main, Cls_tid__main)
.Add_bry_byte(gplx.xowa.wikis.ctgs.Xoa_ctg_mgr.Html__cls__bry, Cls_tid__tree)
.Add_bry_byte(Cls_bry__xnav, Cls_tid__xnav)
;
}

View File

@@ -24,6 +24,6 @@ public class Xoh_lnki_dict_ {
gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Encode(1, bfr, ns_id + 2);
}
public static int Ns_decode(Bry_rdr rdr) {
return rdr.Read_int_by_base85(1) - 2;
return rdr.Read_hzip_int(1) - 2;
}
}

View File

@@ -22,16 +22,20 @@ import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wiki
import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*;
public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
private final Bry_bfr tmp_bfr = Bry_bfr.new_(32);
public int Tid() {return Xoh_hzip_dict_.Tid__lnki;}
public String Key() {return Xoh_hzip_dict_.Key__lnki;}
public byte[] Hook() {return hook;} private byte[] hook;
public Gfo_poolable_itm Encode(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_lnki_parser data = (Xoh_lnki_parser)data_obj;
Xoh_anch_href_itm href = data.Href_itm();
int ns_id = href.Ttl_ns_id(); ;
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_lnki_data data = (Xoh_lnki_data)data_obj;
Xoh_anch_href_data href = data.Href_itm();
int ns_id = href.Ttl_ns_id();
flag_bldr.Set_as_bool(Flag__tid_is_ctg_main , data.Tid_is_ctg_main());
flag_bldr.Set_as_bool(Flag__tid_is_ctg_tree , data.Tid_is_ctg_tree());
flag_bldr.Set_as_bool(Flag__tid_is_ctg_xnav , data.Tid_is_ctg_xnav());
flag_bldr.Set_as_bool(Flag__title_missing_ns , data.Title_missing_ns());
flag_bldr.Set_as_bool(Flag__ttl_is_main_page , href.Ttl_is_main_page());
boolean ns_custom_exists= flag_bldr.Set_as_bool(Flag__ns_custom_exists , href.Ttl_ns_custom() != null);
int title_tid = flag_bldr.Set_as_int(Flag__title_tid , href.Tid() == Xoh_anch_href_itm.Tid__anch ? Xoh_lnki_parser.Title__href : data.Title_tid()); // anchs never have title, so don't bother setting flag;
int title_tid = flag_bldr.Set_as_int(Flag__title_tid , href.Tid() == Xoh_anch_href_data.Tid__anch ? Xoh_lnki_data.Title__href : data.Title_tid()); // anchs never have title, so don't bother setting flag;
flag_bldr.Set_as_bool(Flag__capt_has_ns , data.Capt_has_ns());
boolean ns_is_not_main = flag_bldr.Set_as_bool(Flag__ns_is_not_main , ns_id != Xow_ns_.Tid__main);
int href_type = flag_bldr.Set_as_int(Flag__href_type , href.Tid());
@@ -43,7 +47,7 @@ public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
int flag = flag_bldr.Encode();
bfr.Add(hook);
bfr.Add_hzip_int(1, flag);
if (href_type == Xoh_anch_href_itm.Tid__site) bfr.Add_hzip_mid(src, href.Site_bgn(), href.Site_end());
if (href_type == Xoh_anch_href_data.Tid__site) bfr.Add_hzip_mid(src, href.Site_bgn(), href.Site_end());
if (ns_is_not_main) Xoh_lnki_dict_.Ns_encode(bfr, ns_id);
if (ns_custom_exists) bfr.Add_hzip_bry(href.Ttl_ns_custom());
switch (text_type) {
@@ -57,13 +61,16 @@ public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
bfr.Add_hzip_mid(data.Text_1_src(), data.Text_1_bgn(), data.Text_1_end());
break;
}
if (title_tid == Xoh_lnki_parser.Title__diff) bfr.Add_hzip_mid(src, data.Title_bgn(), data.Title_end());
if (title_tid == Xoh_lnki_data.Title__diff) bfr.Add_hzip_mid(src, data.Title_bgn(), data.Title_end());
hctx.Hzip__stat().Lnki_add(data.Src_end() - data.Src_bgn(), bfr.Len() - bfr_bgn, flag);
return this;
}
public int Decode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, Bry_rdr rdr, byte[] src, int src_bgn, int src_end) {
int flag = rdr.Read_int_by_base85(1); flag_bldr.Decode(flag);
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
int flag = rdr.Read_hzip_int(1); flag_bldr.Decode(flag);
boolean tid_is_ctg_main = flag_bldr.Get_as_bool(Flag__tid_is_ctg_main);
boolean tid_is_ctg_tree = flag_bldr.Get_as_bool(Flag__tid_is_ctg_tree);
boolean tid_is_ctg_xnav = flag_bldr.Get_as_bool(Flag__tid_is_ctg_xnav);
boolean title_missing_ns = flag_bldr.Get_as_bool(Flag__title_missing_ns);
boolean ttl_is_main_page = flag_bldr.Get_as_bool(Flag__ttl_is_main_page);
boolean ns_custom_exists = flag_bldr.Get_as_bool(Flag__ns_custom_exists);
@@ -74,7 +81,7 @@ public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
int capt_cs0_tid = flag_bldr.Get_as_int(Flag__capt_cs0_tid);
byte text_type = flag_bldr.Get_as_byte(Flag__text_type);
int site_bgn = -1, site_end = -1; if (href_type == Xoh_anch_href_itm.Tid__site) {site_bgn = rdr.Pos(); site_end = rdr.Find_fwd_lr();}
int site_bgn = -1, site_end = -1; if (href_type == Xoh_anch_href_data.Tid__site) {site_bgn = rdr.Pos(); site_end = rdr.Find_fwd_lr();}
int ns_id = ns_is_not_main ? Xoh_lnki_dict_.Ns_decode(rdr) : Xow_ns_.Tid__main;
byte[] ns_custom_bry = ns_custom_exists ? rdr.Read_bry_to() : null;
int text_0_bgn = rdr.Pos(); int text_0_end = rdr.Find_fwd_lr();
@@ -84,19 +91,19 @@ public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
text_1_bgn = rdr.Pos(); text_1_end = rdr.Find_fwd_lr();
break;
}
byte[] title_bry = title_tid == Xoh_lnki_parser.Title__diff ? rdr.Read_bry_to() : null;
byte[] title_bry = title_tid == Xoh_lnki_data.Title__diff ? rdr.Read_bry_to() : null;
byte[] href_bry = text_type == Xoh_anch_capt_itm.Tid__less
? tmp_bfr.Add_mid(src, text_0_bgn, text_0_end).Add_mid(src, text_1_bgn, text_1_end).To_bry_and_clear()
: Bry_.Mid(src, text_0_bgn, text_0_end);
byte[] ns_bry = null;
switch (href_type) {
case Xoh_anch_href_itm.Tid__anch: break;
case Xoh_anch_href_itm.Tid__inet: break; //href_bry = Gfo_url_encoder_.Href_qarg.Encode(href_bry); break;
case Xoh_anch_href_itm.Tid__wiki:
case Xoh_anch_href_itm.Tid__site:
case Xoh_anch_href_data.Tid__anch: break;
case Xoh_anch_href_data.Tid__inet: break; //href_bry = Gfo_url_encoder_.Href_qarg.Encode(href_bry); break;
case Xoh_anch_href_data.Tid__wiki:
case Xoh_anch_href_data.Tid__site:
if (ns_custom_exists) {
ns_bry = ns_custom_bry;
tmp_bfr.Add(Xoa_ttl.Replace_spaces(ns_bry)).Add_byte_colon(); // NOTE: Replace_space to handle ns_custom_bry like "Image talk"
tmp_bfr.Add(Xoa_ttl.Replace_spaces(ns_bry)).Add_byte_colon(); // NOTE: Replace_spaces to handle ns_custom_bry like "Image talk"
}
else {
if (ns_id == Xow_ns_.Tid__main) {
@@ -109,67 +116,88 @@ public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
tmp_bfr.Add(ns.Name_db()).Add_byte_colon();
}
}
Gfo_url_encoder encoder = href_type == Xoh_anch_href_itm.Tid__wiki ? Gfo_url_encoder_.Href : Gfo_url_encoder_.Href_qarg;
encoder.Encode(tmp_bfr, href_bry); // encode for href; EX: "/wiki/A's" -> "/wiki/A&27s"
Gfo_url_encoder encoder = href_type == Xoh_anch_href_data.Tid__wiki ? Gfo_url_encoder_.Href : Gfo_url_encoder_.Href_qarg; // NOTE: lnki vs lnke will encode entities differently
int href_end = href_bry.length;
if (tid_is_ctg_xnav) // NOTE: for ctg_xnav, only encode title, not its query arguments; "?" x> "%3F" or "=" x> "%3D" or "sortkey=A B" -> "sortkey=A_B"; DATE:2015-12-28
href_end = Bry_find_.Find_fwd(href_bry, Byte_ascii.Question, 0, href_end); if (href_end == Bry_find_.Not_found) rdr.Err_wkr().Fail("encoded question not found in category xnav link", "href", href_bry);
encoder.Encode(tmp_bfr, href_bry, 0, href_end); // encode for href; EX: "/wiki/A's" -> "/wiki/A&27s"
if (tid_is_ctg_xnav)
tmp_bfr.Add_mid(href_bry, href_end, href_bry.length);
href_bry = tmp_bfr.To_bry_and_clear();
break;
}
byte[] capt_bry = Xoh_lnki_hzip_.Bld_capt(tmp_bfr, href_type, text_type, capt_has_ns, capt_cs0_tid, ns_bry, src, text_0_bgn, text_0_end, src, text_1_bgn, text_1_end);
if (href_type != Xoh_anch_href_itm.Tid__anch) {
if (href_type != Xoh_anch_href_data.Tid__anch) {
switch (title_tid) {
case Xoh_lnki_parser.Title__missing: title_bry = null; break;
case Xoh_lnki_parser.Title__diff: break;
case Xoh_lnki_parser.Title__href: title_bry = Gfo_url_encoder_.Href.Decode(href_bry); break;
case Xoh_lnki_parser.Title__capt: title_bry = !capt_has_ns && !title_missing_ns && ns_bry != null ? Bry_.Add(ns_bry, Byte_ascii.Colon_bry, capt_bry) : capt_bry; break;
case Xoh_lnki_data.Title__missing: title_bry = null; break;
case Xoh_lnki_data.Title__diff: break;
case Xoh_lnki_data.Title__href:
title_bry = tid_is_ctg_main
? Gfo_url_encoder_.Href.Decode(capt_bry)
: Gfo_url_encoder_.Href.Decode(href_bry);
break;
case Xoh_lnki_data.Title__capt:
title_bry = !capt_has_ns && !title_missing_ns && ns_bry != null
? Bry_.Add(ns_bry, Byte_ascii.Colon_bry, capt_bry)
: capt_bry;
break;
}
}
// gen html
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
bfr.Add(Gfh_bldr_.Bry__a_lhs_w_href);
switch (href_type) {
case Xoh_anch_href_itm.Tid__anch:
case Xoh_anch_href_data.Tid__anch:
bfr.Add_byte(Byte_ascii.Hash); // "#"
break;
case Xoh_anch_href_itm.Tid__site:
case Xoh_anch_href_data.Tid__site:
bfr.Add(Xoh_href_.Bry__site).Add_mid(src, site_bgn, site_end);
bfr.Add(Xoh_href_.Bry__wiki);
break;
case Xoh_anch_href_itm.Tid__wiki:
case Xoh_anch_href_data.Tid__wiki:
bfr.Add(Xoh_href_.Bry__wiki);
break;
}
bfr.Add(href_bry);
bfr.Add(href_bry);
if (tid_is_ctg_main)
bfr.Add(Gfh_bldr_.Bry__cls__nth).Add(Xoh_lnki_data.Cls_bry__main);
else if (tid_is_ctg_tree)
bfr.Add(Gfh_bldr_.Bry__cls__nth).Add(gplx.xowa.wikis.ctgs.Xoa_ctg_mgr.Html__cls__bry);
else if (tid_is_ctg_xnav)
bfr.Add(Gfh_bldr_.Bry__cls__nth).Add(Xoh_lnki_data.Cls_bry__xnav);
if (!hctx.Mode_is_diff())
bfr.Add(Html_bldr_.Bry__id__nth).Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(hctx.Lnki__uid__nxt());
if ( href_type != Xoh_anch_href_itm.Tid__anch) { // anchs never have title;
bfr.Add(Gfh_bldr_.Bry__id__nth).Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(hctx.Uid__lnki_nxt());
if ( href_type != Xoh_anch_href_data.Tid__anch) { // anchs never have title;
if (title_bry != null) {
bfr.Add(Html_bldr_.Bry__title__nth);
Html_utl.Escape_html_to_bfr(bfr, title_bry, 0, title_bry.length, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.N);
bfr.Add(Gfh_bldr_.Bry__title__nth);
Gfh_utl.Escape_html_to_bfr(bfr, title_bry, 0, title_bry.length, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.N);
}
}
bfr.Add(Html_bldr_.Bry__lhs_end_head_w_quote);
bfr.Add(Gfh_bldr_.Bry__lhs_end_head_w_quote);
bfr.Add(capt_bry);
bfr.Add(Html_bldr_.Bry__a_rhs);
return rdr.Pos();
bfr.Add(Gfh_bldr_.Bry__a_rhs);
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_lnki_hzip rv = new Xoh_lnki_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ (1 , 1, 1, 2, 1 , 1, 2, 2, 2);
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ (1, 1, 1, 1 , 1, 1, 2, 1 , 1, 2, 2, 2);
private static final int // SERIALIZED
Flag__title_missing_ns = 0 // [[c:]] -> "/site/commons.wikimedia.org/wiki/"
, Flag__ttl_is_main_page = 1 // [[c:]] -> "/site/commons.wikimedia.org/wiki/"
, Flag__ns_custom_exists = 2 // [[c:category:a]] -> "/site/commons.wikimedia.org/wiki/category:a"
, Flag__title_tid = 3 // href, capt, diff, empty; [//en.wikipedia.org] where en.w is local
, Flag__capt_has_ns = 4 // "A" vs "Help:A"
, Flag__ns_is_not_main = 5
, Flag__href_type = 6 // "wiki", "site", "anch", "inet"
, Flag__capt_cs0_tid = 7 // exact, lower, upper
, Flag__text_type = 8 // "same", "diff", "more", "less"
Flag__tid_is_ctg_main = 0
, Flag__tid_is_ctg_tree = 1
, Flag__tid_is_ctg_xnav = 2
, Flag__title_missing_ns = 3 //
, Flag__ttl_is_main_page = 4 // [[c:]] -> "/site/commons.wikimedia.org/wiki/"
, Flag__ns_custom_exists = 5 // [[c:category:a]] -> "/site/commons.wikimedia.org/wiki/category:a"
, Flag__title_tid = 6 // href, capt, diff, empty; [//en.wikipedia.org] where en.w is local
, Flag__capt_has_ns = 7 // "A" vs "Help:A"
, Flag__ns_is_not_main = 8
, Flag__href_type = 9 // "wiki", "site", "anch", "inet"
, Flag__capt_cs0_tid = 10 // exact, lower, upper
, Flag__text_type = 11 // "same", "diff", "more", "less"
;
}
class Xoh_lnki_hzip_ {
public static byte[] Bld_capt(Bry_bfr tmp_bfr, byte href_type, byte text_type, boolean capt_has_ns, int capt_cs0, byte[] ns_bry, byte[] text_0_src, int text_0_bgn, int text_0_end, byte[] capt_src, int text_1_bgn, int text_1_end) {
if ( href_type == Xoh_anch_href_itm.Tid__anch
if ( href_type == Xoh_anch_href_data.Tid__anch
&& text_type != Xoh_anch_capt_itm.Tid__diff )
tmp_bfr.Add_byte(Byte_ascii.Hash);
if (capt_has_ns && ns_bry != null)

View File

@@ -67,4 +67,13 @@ public class Xoh_lnki_hzip__ns__tst {
@Test public void Alias__url_encoding() { // EX: [[Image:Aü.png|b]]
fxt.Test__bicode("~${-f)Image~Aü.png~b~", "<a href='/wiki/Image:A%C3%BC.png' title='Image:Aü.png'>b</a>");
}
@Test public void Ctg__main() { // links at bottom of pages in main ns; DATE:2015-12-28
fxt.Test__bicode("~$|&*G1A~", "<a href='/wiki/Category:A' class='inte" + "rnal' title='A'>A</a>");
}
@Test public void Ctg__tree() { // links on Category pages;
fxt.Test__bicode("~$|#q_1A~", "<a href='/wiki/Category:A' class='CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory'>A</a>");
}
@Test public void Ctg__xnav() { // previous / next 200 links on Category pages
fxt.Test__bicode("~$|\"3/1A B?pageuntil=C, D#mw-pages~previous 200~Category:A_B~", "<a href='/wiki/Category:A_B?pageuntil=C, D#mw-pages' class='xowa_nav' title='Category:A_B'>previous 200</a>");
}
}

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.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
import org.junit.*; import gplx.core.brys.*; import gplx.langs.htmls.parsers.*;
import org.junit.*; import gplx.core.brys.*; import gplx.langs.htmls.docs.*;
public class Xoh_anch_capt_itm_tst {
private final Xoh_anch_capt_itm_fxt fxt = new Xoh_anch_capt_itm_fxt();
@Test public void Basic__same() {fxt.Test__match("Abc" , "Abc", Xoh_anch_capt_itm.Tid__same);}

View File

@@ -17,14 +17,14 @@ 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.langs.htmls.encoders.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*;
public class Xoh_anch_href_itm implements Xoh_itm_parser {
public class Xoh_anch_href_data implements Xoh_itm_parser {
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash);
// private final Xoa_url tmp_url = Xoa_url.blank();
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
public Html_atr Atr() {return atr;} private Html_atr atr;
public Gfh_atr Atr() {return atr;} private Gfh_atr atr;
public byte Tid() {return tid;} private byte tid;
public byte[] Rng_src() {return rng_src;} private byte[] rng_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 Site_bgn() {return site_bgn;} private int site_bgn;
@@ -37,22 +37,21 @@ public class Xoh_anch_href_itm implements Xoh_itm_parser {
public byte[] Ttl_ns_custom() {return ttl_ns_custom;} private byte[] ttl_ns_custom;
public int Ttl_bgn() {return ttl_bgn;} private int ttl_bgn;
public int Ttl_end() {return ttl_end;} private int ttl_end;
private void Clear() {
public void Clear() {
tid = Tid__wiki;
rng_bgn = rng_end = site_bgn = site_end = ttl_bgn = ttl_end = -1;
ttl_full_txt = ttl_page_db = ttl_ns_custom = null;
ttl_ns_id = Xow_ns_.Tid__main;
}
public boolean Parse(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, Html_tag tag) {
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__href);
return Parse(err_wkr, hctx, atr.Val_bgn(), atr.Val_end());
public boolean Parse(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, byte[] src, Gfh_tag tag) {
this.atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__href);
return Parse(err_wkr, hctx, src, atr.Val_bgn(), atr.Val_end());
}
public boolean Parse(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int rng_bgn, int rng_end) {
this.Clear();
public boolean Parse(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, byte[] src, int rng_bgn, int rng_end) {
if (rng_bgn == -1) return false; // no href; return; EX: <a/> vs <a href='a.org'/>
this.rng_src = src;
rdr.Init_by_wkr(err_wkr, "href", rng_bgn, rng_end);
this.rng_bgn = rng_bgn; this.rng_end = rng_end;
byte[] src = err_wkr.Src();
if (rng_end == rng_bgn) { // handle empty String separately; EX: href=""
tid = Tid__inet;
ttl_bgn = ttl_end = 0;
@@ -85,16 +84,8 @@ public class Xoh_anch_href_itm implements Xoh_itm_parser {
return true;
}
private void Parse_inet(Xoh_hdoc_ctx hctx, byte[] src) {
// hctx.Wiki__url_parser().Parse(tmp_url, src);
// Tfds.Write(tmp_url.Tid());
// if (tmp_url.Tid() == Xoa_url_.Tid_page) {
// Tfds.Write(tmp_url.Wiki_bry());
// Tfds.Write(tmp_url.Page_bry());
// }
// else {
tid = Tid__inet;
ttl_bgn = rng_bgn;
// }
}
private void Parse_ttl(Xow_ttl_parser ttl_parser, byte[] src) {
boolean ttl_is_empty = ttl_end - ttl_bgn == 0; // NOTE: ttl can be empty; EX: "href='/site/en.wikipedia.org/wiki/'" "href='/wiki/'"
@@ -104,13 +95,13 @@ public class Xoh_anch_href_itm implements Xoh_itm_parser {
else {
ttl_full_txt = Gfo_url_encoder_.Href_wo_anchor.Decode(src, ttl_bgn, ttl_end);
switch (tid) {
case Xoh_anch_href_itm.Tid__anch:
case Xoh_anch_href_itm.Tid__inet:
case Xoh_anch_href_data.Tid__anch:
case Xoh_anch_href_data.Tid__inet:
ttl_ns_id = Xow_ns_.Tid__main;
ttl_page_db = ttl_full_txt;
break;
case Xoh_anch_href_itm.Tid__wiki:
case Xoh_anch_href_itm.Tid__site:
case Xoh_anch_href_data.Tid__wiki:
case Xoh_anch_href_data.Tid__site:
int ttl_full_len = ttl_full_txt.length;
int colon_pos = Bry_find_.Find_fwd(ttl_full_txt, Byte_ascii.Colon, 0, ttl_full_len);
ttl_page_db = ttl_full_txt;
@@ -133,6 +124,9 @@ public class Xoh_anch_href_itm implements Xoh_itm_parser {
}
}
}
public void Init_by_decode(byte[] anch_href_bry) {
this.rng_src = anch_href_bry; this.rng_bgn = 0; this.rng_end = rng_src.length;
}
public static final byte
Tid__wiki = 0 // EX: href="/wiki/A"
, Tid__site = 1 // EX: href="/site/en.wikipedia.org/wiki/A"

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