mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.11.3.1
This commit is contained in:
@@ -27,7 +27,8 @@ public class Xoh_page implements Xoa_page {
|
||||
public boolean Exists() {return exists;} public Xoh_page Exists_n_() {exists = false; return this;} private boolean exists = true;
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public byte[] Body() {return body;} public void Body_(byte[] v) {this.body = v;} private byte[] body;
|
||||
public byte Body_flag() {return body_flag;} private byte body_flag = Byte_.Max_value_127;
|
||||
public int Body_zip_tid() {return body_zip_tid;} private int body_zip_tid;
|
||||
public int Body_hzip_tid() {return body_hzip_tid;} private int body_hzip_tid;
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
|
||||
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
|
||||
public byte[] Sidebar_div() {return sidebar_div;} private byte[] sidebar_div;
|
||||
@@ -48,9 +49,9 @@ public class Xoh_page implements Xoa_page {
|
||||
this.wiki = wiki; this.page_url = page_url; this.page_ttl = page_ttl; this.page_id = page_id;
|
||||
this.Clear();
|
||||
}
|
||||
public void Ctor_by_db(int head_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte body_flag, byte[] body) {
|
||||
public void Ctor_by_db(int head_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, int zip_tid, int hzip_tid, byte[] body) {
|
||||
head_mgr.Flag_(head_flag);
|
||||
this.display_ttl = display_ttl; this.content_sub = content_sub; this.sidebar_div = sidebar_div; this.body = body; this.body_flag = body_flag;
|
||||
this.display_ttl = display_ttl; this.content_sub = content_sub; this.sidebar_div = sidebar_div; this.body = body; this.body_zip_tid = zip_tid; this.body_hzip_tid = hzip_tid;
|
||||
}
|
||||
public Xoh_page Ctor_by_page(Bry_bfr tmp_bfr, Xoae_page page) {
|
||||
this.page_id = page.Revision_data().Id();
|
||||
@@ -64,6 +65,7 @@ public class Xoh_page implements Xoa_page {
|
||||
return this;
|
||||
}
|
||||
private void Clear() {
|
||||
this.body_zip_tid = -1; this.body_hzip_tid = -1;
|
||||
display_ttl = content_sub = sidebar_div = Bry_.Empty;
|
||||
img_itms = Xohd_img_itm__base.Ary_empty;
|
||||
head_mgr.Clear(); gallery_itms.Clear(); redlink_uids.Clear(); commons_mgr.Clear();
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.portal.*;
|
||||
public class Xoh_page_mgr implements GfoInvkAble {
|
||||
public Xoh_subpages_bldr Subpages_bldr() {return subpages_bldr;} private final Xoh_subpages_bldr subpages_bldr = new Xoh_subpages_bldr();
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xoh_page_wtr_mgr implements GfoInvkAble {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
|
||||
@@ -16,11 +16,12 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.langs.htmls.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.parsers.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.apps.gfs.*; import gplx.xowa.htmls.portal.*;
|
||||
public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
public class Xoh_page_wtr_wkr extends gplx.core.brys.Bfr_arg_base {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private final Object thread_lock_1 = new Object(), thread_lock_2 = new Object();
|
||||
private final Xoh_page_wtr_mgr mgr; private final byte page_mode;
|
||||
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr(); // In other languages
|
||||
@@ -43,14 +44,14 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
break;
|
||||
}
|
||||
Bry_bfr page_bfr = Xoa_app_.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page bfr to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
|
||||
Fmt__do(page_bfr);
|
||||
Bfr_arg__add(page_bfr);
|
||||
Write_page_by_tid(view_mode, bfr, fmtr, page_bfr.To_bry_and_rls());
|
||||
if (page_mode == Xopg_page_.Tid_html) // if html, write page again, but wrap it in html skin this time
|
||||
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Html_utl.Escape_html_as_bry(bfr.To_bry_and_clear()));
|
||||
wdata_lang_wtr.Page_(null);
|
||||
}
|
||||
else
|
||||
Fmt__do(bfr);
|
||||
Bfr_arg__add(bfr);
|
||||
this.page = null;
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
@@ -96,7 +97,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
Xoh_page_wtr_wkr_.Bld_head_end(bfr, page); // add after </head>
|
||||
Xoh_page_wtr_wkr_.Bld_html_end(bfr, page); // add after </html>
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {Write_body(bfr, Xoh_wtr_ctx.Basic, page);}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {Write_body(bfr, Xoh_wtr_ctx.Basic, page);}
|
||||
public void Write_body(Bry_bfr bfr, Xoh_wtr_ctx hctx, Xoae_page page) {
|
||||
synchronized (thread_lock_2) {
|
||||
this.page = page; this.wiki = page.Wikie(); this.app = wiki.Appe();
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xohp_ctg_grp_mgr {
|
||||
final Bry_fmtr grp_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
@@ -42,9 +43,9 @@ public class Xohp_ctg_grp_mgr {
|
||||
grp_fmtr.Bld_bfr_many(bfr, categories_lbl, itm_mgr);
|
||||
}
|
||||
}
|
||||
class Xoh_ctg_itm_fmtr implements Bry_fmtr_arg {
|
||||
class Xoh_ctg_itm_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
public void Set(Xoae_page page, Bry_fmtr itm_fmtr) {this.page = page; this.itm_fmtr = itm_fmtr;} private Xoae_page page; Bry_fmtr itm_fmtr;
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override 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();
|
||||
|
||||
@@ -16,8 +16,9 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Dbui_cells_fmtr implements Bry_fmtr_arg {
|
||||
public class Dbui_cells_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
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;
|
||||
@@ -29,7 +30,7 @@ public class Dbui_cells_fmtr implements Bry_fmtr_arg {
|
||||
this.row_key = row_key; this.row_itm = row_itm;
|
||||
return this;
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override 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
|
||||
@@ -39,12 +40,12 @@ public class Dbui_cells_fmtr implements Bry_fmtr_arg {
|
||||
, " </div>"
|
||||
), "vals", "btns");
|
||||
}
|
||||
class Dbui_cell_fmtr implements Bry_fmtr_arg {
|
||||
class Dbui_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
private byte[] row_key; private Dbui_row_itm row_itm;
|
||||
private Dbui_val_fmtr val_fmtr;
|
||||
public void Ctor(Dbui_val_fmtr val_fmtr) {this.val_fmtr = val_fmtr;}
|
||||
public Dbui_cell_fmtr Init(byte[] row_key, Dbui_row_itm row_itm) {this.row_key = row_key; this.row_itm = row_itm; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override 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) {
|
||||
@@ -57,12 +58,12 @@ class Dbui_cell_fmtr implements Bry_fmtr_arg {
|
||||
, " <div class='xo_cell'>~{html}</div>"
|
||||
), "row_key", "val_idx", "html");
|
||||
}
|
||||
class Dbui_btn_fmtr implements Bry_fmtr_arg {
|
||||
class Dbui_btn_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
private byte[] row_key; private Dbui_btn_itm[] btns;
|
||||
public Dbui_btn_fmtr Init(byte[] row_key, Dbui_btn_itm[] btns) {
|
||||
this.row_key = row_key; this.btns = btns; return this;
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override 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) {
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.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_tbl_fmtr {
|
||||
private final Dbui_head_cell_fmtr head_cell_fmtr = new Dbui_head_cell_fmtr();
|
||||
@@ -32,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 implements Bry_fmtr_arg {
|
||||
class Dbui_head_cell_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
private Dbui_tbl_itm tbl;
|
||||
public Dbui_head_cell_fmtr Init(Dbui_tbl_itm tbl) {this.tbl = tbl; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override 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];
|
||||
@@ -48,13 +49,13 @@ class Dbui_head_cell_fmtr implements Bry_fmtr_arg {
|
||||
, " <div class='xo_head xo_resizable_col' style='width:~{width}px;'>~{display}</div>"
|
||||
), "width", "display");
|
||||
}
|
||||
class Dbui_row_fmtr implements Bry_fmtr_arg {
|
||||
class Dbui_row_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
private final Dbui_cells_fmtr cells_fmtr = new Dbui_cells_fmtr();
|
||||
private final Dbui_val_fmtr val_fmtr = Dbui_val_fmtr_.new_view();
|
||||
private final Bry_bfr row_key_bfr = Bry_bfr.new_(255);
|
||||
private Dbui_tbl_itm tbl; private Dbui_row_itm[] rows;
|
||||
public Dbui_row_fmtr Init(Dbui_tbl_itm tbl, Dbui_row_itm[] rows) {this.tbl = tbl; this.rows = rows; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override 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());
|
||||
|
||||
@@ -16,21 +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.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 interface Dbui_val_fmtr {
|
||||
Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val);
|
||||
}
|
||||
class Dbui_val_fmtr__view implements Bry_fmtr_arg, Dbui_val_fmtr {
|
||||
class Dbui_val_fmtr__view extends gplx.core.brys.Bfr_arg_base implements Dbui_val_fmtr {
|
||||
private Dbui_val_itm val;
|
||||
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.val = val; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add(val.Html());
|
||||
}
|
||||
}
|
||||
class Dbui_val_fmtr__edit implements Bry_fmtr_arg, Dbui_val_fmtr {
|
||||
class Dbui_val_fmtr__edit extends gplx.core.brys.Bfr_arg_base implements Dbui_val_fmtr {
|
||||
private Dbui_col_itm col; private byte[] row_id; private Dbui_val_itm val;
|
||||
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.col = col; this.row_id = row_id; this.val = val; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override 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;
|
||||
|
||||
@@ -16,15 +16,19 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
public class Xow_hdump_mgr {
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
|
||||
public Xow_hdump_mgr(Xow_wiki wiki) {
|
||||
this.hzip_mgr = new Xow_hzip_mgr(wiki);
|
||||
this.save_mgr = new Xow_hdump_mgr__save(wiki, hzip_mgr, tmp_hpg, tmp_bfr);
|
||||
this.load_mgr = new Xow_hdump_mgr__load(wiki, hzip_mgr, tmp_hpg, tmp_bfr);
|
||||
this.save_mgr = new Xow_hdump_mgr__save(wiki, hzip_mgr, zip_mgr, tmp_hpg, tmp_bfr);
|
||||
this.load_mgr = new Xow_hdump_mgr__load(wiki, hzip_mgr, zip_mgr, tmp_hpg, tmp_bfr);
|
||||
}
|
||||
public Xow_hdump_mgr__save Save_mgr() {return save_mgr;} private Xow_hdump_mgr__save save_mgr;
|
||||
public Xow_hdump_mgr__load Load_mgr() {return load_mgr;} private Xow_hdump_mgr__load load_mgr;
|
||||
public Xoh_hzip_mgr Hzip_mgr() {return hzip_mgr;} private final Xoh_hzip_mgr hzip_mgr = new Xoh_hzip_mgr();
|
||||
public void Init_by_db(Xow_wiki wiki) {
|
||||
byte default_zip_tid = gplx.core.ios.Io_stream_.Tid_raw;
|
||||
boolean default_hzip_enable = false;
|
||||
@@ -33,12 +37,10 @@ public class Xow_hdump_mgr {
|
||||
default_zip_tid = props.Zip_tid_html();
|
||||
default_hzip_enable = props.Hzip_enabled();
|
||||
}
|
||||
Init_by_db(wiki, default_zip_tid, default_hzip_enable);
|
||||
Init_by_db(default_zip_tid, default_hzip_enable);
|
||||
}
|
||||
public void Init_by_db(Xow_wiki wiki, byte default_zip_tid, boolean default_hzip_enable) {
|
||||
hzip_mgr.Init_by_atrs(default_zip_tid, default_hzip_enable);
|
||||
public void Init_by_db(byte default_zip_tid, boolean default_hzip_enable) {
|
||||
int dflt_hzip_tid = default_hzip_enable ? Xoh_hzip_dict_.Hzip__none : Xoh_hzip_dict_.Hzip__v1;
|
||||
save_mgr.Init_by_db(default_zip_tid, dflt_hzip_tid);
|
||||
}
|
||||
public Xow_hzip_mgr Hzip_mgr() {return hzip_mgr;} private Xow_hzip_mgr hzip_mgr;
|
||||
public Xow_hdump_mgr__save Save_mgr() {return save_mgr;} private Xow_hdump_mgr__save save_mgr;
|
||||
public Xow_hdump_mgr__load Load_mgr() {return load_mgr;} private Xow_hdump_mgr__load load_mgr;
|
||||
}
|
||||
|
||||
@@ -16,14 +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; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
public class Xow_hdump_mgr__load {
|
||||
private final Xow_wiki wiki; private final Xow_hzip_mgr hzip_mgr;
|
||||
private final Xoh_page tmp_hpg; private final Xowd_page_itm tmp_dbpg = new Xowd_page_itm();
|
||||
public Xow_hdump_mgr__load(Xow_wiki wiki, Xow_hzip_mgr hzip_mgr, Xoh_page tmp_hpg, Bry_bfr tmp_bfr) {
|
||||
this.wiki = wiki; this.hzip_mgr = hzip_mgr; this.tmp_hpg = tmp_hpg;
|
||||
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();
|
||||
public Xow_hdump_mgr__load(Xow_wiki wiki, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, Xoh_page tmp_hpg, Bry_bfr tmp_bfr) {
|
||||
this.wiki = wiki; this.hzip_mgr = hzip_mgr; this.zip_mgr = zip_mgr; this.tmp_hpg = tmp_hpg; this.tmp_bfr = tmp_bfr;
|
||||
this.make_mgr = new Xoh_make_mgr(wiki.App().Usr_dlg(), wiki.App().Fsys_mgr(), Xoa_app_.Utl__encoder_mgr().Fsys(), wiki.Domain_bry());
|
||||
}
|
||||
public Xoh_make_mgr Make_mgr() {return make_mgr;} private final Xoh_make_mgr make_mgr;
|
||||
@@ -32,33 +33,26 @@ public class Xow_hdump_mgr__load {
|
||||
wpg.Hdump_data().Body_(tmp_hpg.Body());
|
||||
// wpg.Root_(new Xop_root_tkn());
|
||||
Fill_page(wpg, tmp_hpg);
|
||||
// foreach (gplx.xowa.htmls.core.makes.imgs.Xohd_img_itm__base itm in hpg.Img_itms())
|
||||
// wpg.Hdump_data().Imgs_add(itm);
|
||||
}
|
||||
public boolean Load(Xoh_page hpg, Xoa_ttl ttl) {
|
||||
synchronized (tmp_dbpg) {
|
||||
if (!Load__dbpg(tmp_dbpg.Clear(), hpg, ttl)) return Load__fail(hpg); // nothing in "page" table
|
||||
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_page().Select_by_page(hpg)) return Load__fail(hpg); // nothing in "html_page" table
|
||||
byte[] src = hzip_mgr.Parse(hpg.Url_bry_safe(), hpg.Body_flag(), hpg.Body());
|
||||
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()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private boolean Load__fail(Xoh_page hpg) {hpg.Exists_n_(); return false;}
|
||||
private boolean Load__dbpg(Xowd_page_itm dbpg, Xoh_page hpg, Xoa_ttl ttl) {
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_ttl(dbpg, ttl.Ns(), ttl.Page_db());
|
||||
if (dbpg.Redirect_id() != -1) Load__dbpg__redirects(dbpg);
|
||||
return dbpg.Html_db_id() != -1;
|
||||
}
|
||||
private void Load__dbpg__redirects(Xowd_page_itm dbpg) {
|
||||
int redirect_count = 0;
|
||||
while (redirect_count < 5) {
|
||||
int redirect_id = dbpg.Redirect_id();
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_id(dbpg, redirect_id);
|
||||
if (redirect_id == -1) break;
|
||||
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) {
|
||||
hzip_mgr.Decode(tmp_bfr.Clear(), wiki, hpg, src);
|
||||
src = tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
return src;
|
||||
}
|
||||
private void Fill_page(Xoae_page wpg, Xoh_page hpg) {
|
||||
Xopg_html_data html_data = wpg.Html_data();
|
||||
@@ -72,4 +66,18 @@ public class Xow_hdump_mgr__load {
|
||||
wpg_head.Itm__gallery().Enabled_ (hpg_head.Gallery_packed_exists());
|
||||
wpg_head.Itm__hiero().Enabled_ (hpg_head.Hiero_exists());
|
||||
}
|
||||
private static boolean Load__fail(Xoh_page hpg) {hpg.Exists_n_(); return false;}
|
||||
private static boolean Load__dbpg(Xow_wiki wiki, Xowd_page_itm dbpg, Xoh_page hpg, Xoa_ttl ttl) {
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_ttl(dbpg, ttl.Ns(), ttl.Page_db());
|
||||
if (dbpg.Redirect_id() != -1) Load__dbpg__redirects(wiki, dbpg);
|
||||
return dbpg.Html_db_id() != -1;
|
||||
}
|
||||
private static void Load__dbpg__redirects(Xow_wiki wiki, Xowd_page_itm dbpg) {
|
||||
int redirect_count = 0;
|
||||
while (redirect_count < 5) {
|
||||
int redirect_id = dbpg.Redirect_id();
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_id(dbpg, redirect_id);
|
||||
if (redirect_id == -1) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class Xodb_hdump_mgr__base_fxt {
|
||||
wiki = fxt.Wiki();
|
||||
page = wiki.Parser_mgr().Ctx().Cur_page();
|
||||
hdump_mgr = wiki.Html__hdump_mgr();
|
||||
hdump_mgr.Init_by_db(wiki, gplx.core.ios.Io_stream_.Tid_raw, false);
|
||||
hdump_mgr.Init_by_db(gplx.core.ios.Io_stream_.Tid_raw, false);
|
||||
}
|
||||
fxt.Reset();
|
||||
page.Revision_data().Id_(0);
|
||||
@@ -127,7 +127,7 @@ class Xodb_hdump_mgr__base_fxt {
|
||||
@gplx.Virtual public void Exec_write(String raw) {
|
||||
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
page.Root_(root);
|
||||
hdump_mgr.Save_mgr().Make_body_as_hswap(page);
|
||||
hdump_mgr.Save_mgr().Bld_hdump(page);
|
||||
}
|
||||
public Xohd_img_itm__base Make_xfer(String lnki_ttl, int html_uid, int html_w, int html_h, boolean file_is_orig, int file_ext_id) {
|
||||
return new Xohd_img_itm__img().Data_init_base
|
||||
|
||||
@@ -16,49 +16,52 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*; import gplx.xowa.htmls.heads.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.heads.*;
|
||||
import gplx.core.ios.*; import gplx.core.primitives.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xow_hdump_mgr__save {
|
||||
private final Xow_wiki wiki; private final Xow_hzip_mgr hzip_mgr;
|
||||
private final Xoh_page tmp_hpg; private final Bry_bfr tmp_bfr; private boolean html_db_is_new = false;
|
||||
public Xow_hdump_mgr__save(Xow_wiki wiki, Xow_hzip_mgr hzip_mgr, Xoh_page tmp_hpg, Bry_bfr tmp_bfr) {
|
||||
this.wiki = wiki; this.hzip_mgr = hzip_mgr;
|
||||
this.tmp_hpg = tmp_hpg; this.tmp_bfr = tmp_bfr;
|
||||
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 Bool_obj_ref html_db_is_new = Bool_obj_ref.n_();
|
||||
private int dflt_zip_tid, dflt_hzip_tid;
|
||||
public Xow_hdump_mgr__save(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;
|
||||
}
|
||||
public void Init_by_db(int dflt_zip_tid, int dflt_hzip_tid) {this.dflt_zip_tid = dflt_zip_tid; this.dflt_hzip_tid = dflt_hzip_tid;}
|
||||
public int Save(Xoae_page page) {
|
||||
synchronized (tmp_hpg) {
|
||||
Make_body_as_hswap(page);
|
||||
Bld_hdump(page);
|
||||
tmp_hpg.Ctor_by_page(tmp_bfr, page);
|
||||
this.html_db_is_new = false;
|
||||
Xowd_db_file html_db = Get_html_db(page);
|
||||
return Save(tmp_hpg, html_db, html_db_is_new);
|
||||
Xowd_db_file html_db = Get_html_db(wiki, page, html_db_is_new.Val_n_());
|
||||
return Save(tmp_hpg, html_db, html_db_is_new.Val());
|
||||
}
|
||||
}
|
||||
public int Save(Xoh_page hpg, Xowd_db_file html_db, boolean insert) {
|
||||
byte db_body_flag = hzip_mgr.Body_flag();
|
||||
byte[] db_body = hzip_mgr.Write(hpg.Url_bry_safe(), db_body_flag, hpg.Body());
|
||||
if (insert)
|
||||
html_db.Tbl__html_page().Insert(hpg, db_body_flag, db_body);
|
||||
else
|
||||
html_db.Tbl__html_page().Update(hpg, db_body_flag, db_body);
|
||||
byte[] db_body = Write(tmp_bfr, wiki, hpg, hzip_mgr, zip_mgr, dflt_zip_tid, dflt_hzip_tid, hpg.Body());
|
||||
if (insert) html_db.Tbl__html().Insert(hpg, dflt_zip_tid, dflt_hzip_tid, db_body);
|
||||
else html_db.Tbl__html().Update(hpg, dflt_zip_tid, dflt_hzip_tid, db_body);
|
||||
return db_body.length;
|
||||
}
|
||||
public void Make_body_as_hswap(Xoae_page page) {
|
||||
public void Bld_hdump(Xoae_page page) {
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will keep incrementing upwards
|
||||
wiki.Html__wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page); // save as hdump_fmt
|
||||
page.Hdump_data().Body_(tmp_bfr.To_bry_and_clear());
|
||||
}
|
||||
private Xowd_db_file Get_html_db(Xoae_page page) {
|
||||
private static byte[] Write(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1) {
|
||||
hzip_mgr.Encode(bfr.Clear(), wiki, hpg, src);
|
||||
src = bfr.To_bry_and_rls();
|
||||
}
|
||||
if (zip_tid > gplx.core.ios.Io_stream_.Tid_raw)
|
||||
src = zip_mgr.Zip((byte)zip_tid, src);
|
||||
return src;
|
||||
}
|
||||
private static Xowd_db_file Get_html_db(Xow_wiki wiki, Xoae_page page, Bool_obj_ref html_db_is_new) {
|
||||
Xowd_db_file rv = Xowd_db_file.Null;
|
||||
Xowd_db_mgr core_data_mgr = wiki.Data__core_mgr();
|
||||
int html_db_id = page.Revision_data().Html_db_id();
|
||||
if (html_db_id == -1) {
|
||||
html_db_is_new = true;
|
||||
html_db_is_new.Val_y_();
|
||||
rv = core_data_mgr.Db__html();
|
||||
if (rv == null) {
|
||||
rv = core_data_mgr.Dbs__make_by_tid(Xowd_db_file_.Tid_html_data);
|
||||
rv.Tbl__html_redlink().Create_tbl();
|
||||
}
|
||||
if (rv == null) rv = core_data_mgr.Dbs__make_by_tid(Xowd_db_file_.Tid_html_data);
|
||||
html_db_id = rv.Id();
|
||||
page.Revision_data().Html_db_id_(html_db_id);
|
||||
core_data_mgr.Tbl__page().Update__html_db_id(page.Revision_data().Id(), html_db_id);
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xob_hdump_mgr {
|
||||
private final Xowe_wiki wiki; private final Xow_hdump_mgr hdump_mgr;
|
||||
@@ -25,8 +25,8 @@ public class Xob_hdump_mgr {
|
||||
private final Hzip_stat_tbl stats_tbl; private final Hzip_stat_itm tmp_stat_itm;
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
|
||||
public Xob_hdump_mgr(Xowe_wiki wiki, Db_conn make_conn, long hdump_db_max, byte zip_tid, boolean hzip_enabled) {
|
||||
this.wiki = wiki; this.hdump_mgr = wiki.Html__hdump_mgr(); this.tmp_stat_itm = hdump_mgr.Hzip_mgr().Stat_itm();
|
||||
hdump_mgr.Hzip_mgr().Init_by_atrs(zip_tid, hzip_enabled);
|
||||
this.wiki = wiki; this.hdump_mgr = wiki.Html__hdump_mgr(); this.tmp_stat_itm = hdump_mgr.Hzip_mgr().Hctx().Bicode__stat();
|
||||
hdump_mgr.Init_by_db(zip_tid, hzip_enabled);
|
||||
this.stats_tbl = new Hzip_stat_tbl(make_conn);
|
||||
Xowd_db_mgr core_data_mgr = wiki.Db_mgr_as_sql().Core_data_mgr();
|
||||
this.ns_to_db_mgr = new Xob_ns_to_db_mgr(new Xob_ns_to_db_wkr__html(core_data_mgr.Db__core()), core_data_mgr, hdump_db_max);
|
||||
@@ -35,9 +35,7 @@ public class Xob_hdump_mgr {
|
||||
public void Insert(Xoae_page page) {
|
||||
Make_page_body(page);
|
||||
Xowd_db_file html_db = ns_to_db_mgr.Get_by_ns(page.Ttl().Ns().Bldr_data(), prv_row_len); // get html_db
|
||||
synchronized (tmp_hpg) {
|
||||
this.prv_row_len = hdump_mgr.Save_mgr().Save(tmp_hpg.Ctor_by_page(tmp_bfr, page), html_db, true); // save to db
|
||||
}
|
||||
this.prv_row_len = hdump_mgr.Save_mgr().Save(tmp_hpg.Ctor_by_page(tmp_bfr, page), html_db, true); // save to db
|
||||
stats_tbl.Insert(tmp_hpg, tmp_stat_itm, page.Root().Root_src().length, tmp_hpg.Body().length, prv_row_len); // save stats
|
||||
}
|
||||
public void Bld_term() {this.Commit(); ns_to_db_mgr.Rls_all();}
|
||||
|
||||
@@ -23,7 +23,7 @@ class Xob_ns_to_db_wkr__html implements Xob_ns_to_db_wkr {
|
||||
public Xob_ns_to_db_wkr__html(Xowd_db_file page_db) {this.page_db = page_db;}
|
||||
public byte Db_tid() {return Xowd_db_file_.Tid_html_data;}
|
||||
public void Tbl_init(Xowd_db_file db) {
|
||||
Xoh_page_tbl tbl = db.Tbl__html_page();
|
||||
Xoh_page_tbl tbl = db.Tbl__html();
|
||||
tbl.Create_tbl();
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ public class Xob_redlink_mkr_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
Db_attach_rdr attach_rdr = new Db_attach_rdr(link_dump_db.Conn(), "page_db", core_db.Url());
|
||||
attach_rdr.Attach();
|
||||
Xowd_page_tbl page_tbl = core_db.Tbl__page();
|
||||
int cur_html_db_id = -1, cur_page_id = -1; Xoh_redlink_tbl redlink_tbl = null;
|
||||
int cur_html_db_id = -1, cur_page_id = -1;
|
||||
Xoh_redlink_tbl redlink_tbl = new Xoh_redlink_tbl(page_tbl.Conn());
|
||||
Db_rdr rdr = attach_rdr.Exec_as_rdr(Sql_select);
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
@@ -41,7 +42,7 @@ public class Xob_redlink_mkr_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
int html_db_id = rdr.Read_int(page_tbl.Fld_html_db_id());
|
||||
if (html_db_id != cur_html_db_id) {
|
||||
if (redlink_tbl != null) redlink_tbl.Conn().Txn_end();
|
||||
redlink_tbl = wiki.Data__core_mgr().Dbs__get_at(html_db_id).Tbl__html_redlink();
|
||||
// redlink_tbl = wiki.Data__core_mgr().Dbs__get_at(html_db_id).Tbl__html_redlink();
|
||||
redlink_tbl.Conn().Txn_bgn("bldr__redlink");
|
||||
cur_html_db_id = html_db_id;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,12 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.dbs.*; import gplx.core.brys.*;
|
||||
public class Xoh_page_tbl implements RlsAble {
|
||||
private final String tbl_name = "html_page"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String tbl_name = "html"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_page_id, fld_head_flag, fld_body_flag, fld_display_ttl, fld_content_sub, fld_sidebar_div, fld_body;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert, stmt_delete, stmt_update;
|
||||
private final Int_flag_bldr body_flag_bldr = new Int_flag_bldr().Pow_ary_bld_(3, 2); // 8 different zip types; 4 different hzip types
|
||||
public Xoh_page_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.fld_page_id = flds.Add_int_pkey("page_id");
|
||||
@@ -34,18 +35,20 @@ public class Xoh_page_tbl implements RlsAble {
|
||||
}
|
||||
public Db_conn Conn() {return conn;}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("html_page__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_bgn() {conn.Txn_bgn("html__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert(Xoh_page hpg, byte db_body_flag, byte[] body) {Insert(hpg.Page_id(), hpg.Head_mgr().Flag(), db_body_flag, hpg.Display_ttl(), hpg.Content_sub(), hpg.Sidebar_div(), body);}
|
||||
public void Insert(int page_id, int head_flag, int body_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
public void Insert(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] body) {Insert(hpg.Page_id(), hpg.Head_mgr().Flag(), zip_tid, hzip_tid, hpg.Display_ttl(), hpg.Content_sub(), hpg.Sidebar_div(), body);}
|
||||
public void Insert(int page_id, int head_flag, int zip_tid, int hzip_tid, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
int body_flag = body_flag_bldr.Set(0, zip_tid).Set(1, hzip_tid).Encode();
|
||||
stmt_insert.Clear().Val_int(fld_page_id, page_id);
|
||||
Fill_stmt(stmt_insert, head_flag, body_flag, display_ttl, content_sub, sidebar_div, body);
|
||||
stmt_insert.Exec_insert();
|
||||
}
|
||||
public void Update(Xoh_page hpg, byte db_body_flag, byte[] body) {Update(hpg.Page_id(), hpg.Head_mgr().Flag(), db_body_flag, hpg.Display_ttl(), hpg.Content_sub(), hpg.Sidebar_div(), body);}
|
||||
public void Update(int page_id, int head_flag, int body_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
public void Update(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] body) {Update(hpg.Page_id(), hpg.Head_mgr().Flag(), zip_tid, hzip_tid, hpg.Display_ttl(), hpg.Content_sub(), hpg.Sidebar_div(), body);}
|
||||
public void Update(int page_id, int head_flag, int zip_tid, int hzip_tid, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
if (stmt_update == null) stmt_update = conn.Stmt_update_exclude(tbl_name, flds, fld_page_id);
|
||||
int body_flag = body_flag_bldr.Set(0, zip_tid).Set(1, hzip_tid).Encode();
|
||||
stmt_update.Clear();
|
||||
Fill_stmt(stmt_update, head_flag, body_flag, display_ttl, content_sub, sidebar_div, body);
|
||||
stmt_update.Crt_int(fld_page_id, page_id).Exec_update();
|
||||
@@ -59,7 +62,9 @@ public class Xoh_page_tbl implements RlsAble {
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_page_id, hpg.Page_id()).Exec_select__rls_manual();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
hpg.Ctor_by_db(rdr.Read_int(fld_head_flag), rdr.Read_bry_by_str(fld_display_ttl), rdr.Read_bry_by_str(fld_content_sub), rdr.Read_bry_by_str(fld_sidebar_div), (byte)rdr.Read_int(fld_body_flag), rdr.Read_bry(fld_body));
|
||||
int body_flag = rdr.Read_int(fld_body_flag);
|
||||
body_flag_bldr.Decode(body_flag);
|
||||
hpg.Ctor_by_db(rdr.Read_int(fld_head_flag), rdr.Read_bry_by_str(fld_display_ttl), rdr.Read_bry_by_str(fld_content_sub), rdr.Read_bry_by_str(fld_sidebar_div), body_flag_bldr.Get_as_int(0), body_flag_bldr.Get_as_int(1), rdr.Read_bry(fld_body));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -15,7 +15,7 @@ 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.stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public class Hzip_stat_itm {
|
||||
public void Clear() {
|
||||
a_rhs = lnki_text_n = lnki_text_y = lnke_txt = lnke_brk_text_n = lnke_brk_text_y = 0;
|
||||
@@ -15,7 +15,7 @@ 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.stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Hzip_stat_tbl implements RlsAble {
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_decode_ctx {
|
||||
private byte[] dir__file;
|
||||
public Xof_url_bldr Url_bldr() {return url_bldr;} private Xof_url_bldr url_bldr = new Xof_url_bldr();
|
||||
public byte[] Dir__root() {return dir__root;} private byte[] dir__root;
|
||||
public byte[] Dir__file__comm() {return dir__file__comm;} private byte[] dir__file__comm;
|
||||
public byte[] Dir__file__wiki() {return dir__file__wiki;} private byte[] dir__file__wiki;
|
||||
public Xow_ttl_parser Ttl_parser() {return ttl_parser;} private Xow_ttl_parser ttl_parser;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
Xoa_fsys_mgr fsys_mgr = app.Fsys_mgr();
|
||||
this.dir__root = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
this.dir__file = fsys_mgr.File_dir().To_http_file_bry();
|
||||
this.dir__file__comm = Bry_.Add(dir__file, Xow_domain_itm_.Bry__commons, Byte_ascii.Slash_bry);
|
||||
}
|
||||
public void Init_by_page(Xow_wiki wiki) {
|
||||
if (dir__root == null) Init_by_app(wiki.App()); // LAZY INIT
|
||||
this.ttl_parser = wiki;
|
||||
this.dir__file__wiki = Bry_.Add(dir__file, wiki.Domain_bry(), Byte_ascii.Slash_bry);
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.htmls.core.wkrs.spaces.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.escapes.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
public class Xoh_hzip_dict_ {
|
||||
public static final byte Escape = Byte_.By_int(27); // SERIALIZED: 27=escape byte
|
||||
public static final byte[] Escape_bry = Bry_.new_ints(27); // SERIALIZED
|
||||
@@ -29,6 +27,7 @@ public class Xoh_hzip_dict_ {
|
||||
, Tid__lnke = 2 + Base85_ascii
|
||||
, Tid__lnki = 3 + Base85_ascii
|
||||
, Tid__img = 4 + Base85_ascii
|
||||
, Tid__thm = 5 + Base85_ascii
|
||||
, Tid__escape = 84 + Base85_ascii
|
||||
;
|
||||
public static final byte[]
|
||||
@@ -38,6 +37,7 @@ public class Xoh_hzip_dict_ {
|
||||
, Bry__lnke = Bry_.new_ints(Escape, Tid__lnke)
|
||||
, Bry__lnki = Bry_.new_ints(Escape, Tid__lnki)
|
||||
, Bry__img = Bry_.new_ints(Escape, Tid__img)
|
||||
, Bry__thm = Bry_.new_ints(Escape, Tid__thm)
|
||||
;
|
||||
public static final String
|
||||
Key__escape = "escape"
|
||||
@@ -46,22 +46,7 @@ public class Xoh_hzip_dict_ {
|
||||
, Key__lnke = "lnke"
|
||||
, Key__lnki = "lnki"
|
||||
, Key__img = "img"
|
||||
, Key__thm = "thm"
|
||||
;
|
||||
public static Xoh_hzip_wkr To_wkr(byte tid) {
|
||||
switch (tid) {
|
||||
case Tid__escape: return Wkr__escape;
|
||||
case Tid__space: return Wkr__space;
|
||||
case Tid__hdr: return Wkr__hdr;
|
||||
case Tid__lnke: return Wkr__lnke;
|
||||
case Tid__lnki: return Wkr__lnki;
|
||||
case Tid__img: return Wkr__img;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static final Xoh_escape_hzip Wkr__escape = new Xoh_escape_hzip();
|
||||
public static final Xoh_space_hzip Wkr__space = new Xoh_space_hzip();
|
||||
public static final Xoh_hdr_hzip Wkr__hdr = new Xoh_hdr_hzip();
|
||||
public static final Xoh_lnke_hzip Wkr__lnke = new Xoh_lnke_hzip();
|
||||
public static final Xoh_lnki_hzip Wkr__lnki = new Xoh_lnki_hzip();
|
||||
public static final Xoh_img_hzip Wkr__img = new Xoh_img_hzip();
|
||||
public static final int Hzip__none = 0, Hzip__v1 = 1;
|
||||
}
|
||||
|
||||
84
400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_fxt.java
Normal file
84
400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_fxt.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_hzip_fxt {
|
||||
private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final Xoh_hzip_mgr hzip_mgr;
|
||||
private final Xoh_page hpg = new Xoh_page();
|
||||
public Xoh_hzip_fxt() {
|
||||
Xowe_wiki wiki = parser_fxt.Wiki();
|
||||
Xoa_app_fxt.repo2_(parser_fxt.App(), wiki); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
|
||||
wiki.Html__hdump_mgr().Init_by_db(parser_fxt.Wiki());
|
||||
this.hzip_mgr = parser_fxt.Wiki().Html__hdump_mgr().Hzip_mgr();
|
||||
hpg.Init(wiki, Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1);
|
||||
}
|
||||
public void Test__bicode(String hzip, String html) {Test__bicode(hzip, html, html);}
|
||||
public void Test__bicode(String hzip, String html_enc, String html_dec) {
|
||||
hzip = Html_utl.Replace_apos(Xoh_hzip_fxt.Escape(hzip));
|
||||
html_enc = Html_utl.Replace_apos(html_enc);
|
||||
html_dec = Html_utl.Replace_apos(html_dec);
|
||||
Test__encode__raw(hzip, html_enc);
|
||||
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);
|
||||
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);
|
||||
Test__decode__raw(hzip, html);
|
||||
}
|
||||
public void Test__encode__fail(String expd, String html) {
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(html));
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
private void Test__encode__raw(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(html));
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
Tfds.Eq_str_lines(hzip, bfr.To_str_and_clear());
|
||||
}
|
||||
private void Test__decode__raw(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
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());
|
||||
}
|
||||
public void Exec_write_to_fsys(Io_url dir, String fil) {
|
||||
try {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Io_mgr.Instance.LoadFilBry(dir.GenSubFil(fil)));
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
byte[] actl = bfr.To_bry_and_clear();
|
||||
Io_mgr.Instance.SaveFilBry(dir.GenSubFil(fil).GenNewExt(".hzip.html"), actl);
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_hzip.Md5_depth = 4;
|
||||
hzip_mgr.Decode(bfr, parser_fxt.Wiki(), hpg, actl);
|
||||
gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_hzip.Md5_depth = 2;
|
||||
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);
|
||||
}
|
||||
}
|
||||
public static String Escape(String v) {return String_.Replace(v, "~", "");}
|
||||
}
|
||||
@@ -17,41 +17,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
public class Xoh_hzip_mgr {
|
||||
private final Xoh_hdoc_parser hdoc_parser = new Xoh_hdoc_parser(new Xoh_hdoc_wkr__hzip());
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Xoh_hzip_dict_.Escape);
|
||||
private final Xoh_hdoc_wkr__base hdoc_parser = new Xoh_hdoc_wkr__base(new Xoh_hdoc_wkr__hzip());
|
||||
private final Xoh_decode_ctx decode_ctx = new Xoh_decode_ctx();
|
||||
public void Init_by_app(Xoa_app app) {decode_ctx.Init_by_app(app);}
|
||||
public void Encode(Bry_bfr bfr, Xow_wiki wiki, byte[] page_url, byte[] src, Hzip_stat_itm stat_itm) {
|
||||
hdoc_parser.Parse(bfr, wiki, null, page_url, src);
|
||||
public 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 void Encode(Bry_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);
|
||||
}
|
||||
public byte[] Decode(Bry_bfr bfr, Xow_wiki wiki, byte[] page_url, byte[] src) {
|
||||
bfr.Clear();
|
||||
((gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_hzip)Xoh_hzip_dict_.To_wkr(Xoh_hzip_dict_.Tid__lnki)).Ttl_parser_(wiki);
|
||||
int pos = 0, add_bgn = -1; int src_len = src.length;
|
||||
rdr.Ctor_by_page(page_url, src, src_len);
|
||||
decode_ctx.Init_by_page(wiki);
|
||||
public void Decode(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src) {
|
||||
byte[] page_url = hpg.Url_bry_safe();
|
||||
hctx.Init_by_page(wiki, page_url);
|
||||
int pos = 0, txt_bgn = -1, src_len = src.length;
|
||||
rdr.Init_by_page(page_url, src, src_len);
|
||||
while (pos < src_len) {
|
||||
if (src[pos] == Xoh_hzip_dict_.Escape) {
|
||||
if (add_bgn != -1) {bfr.Add_mid(src, add_bgn, pos); add_bgn = -1;}
|
||||
if (txt_bgn != -1) {bfr.Add_mid(src, txt_bgn, pos); txt_bgn = -1;} // handle pending txt
|
||||
int nxt_pos = pos + 1; if (nxt_pos == src_len) break; // handle escape at end of document
|
||||
Xoh_hzip_wkr wkr = hctx.Mkr().Hzip__wkr(src[nxt_pos]);
|
||||
try {
|
||||
Xoh_hzip_wkr wkr = Xoh_hzip_dict_.To_wkr(src[pos + 1]);
|
||||
rdr.Init_by_hook(wkr.Key(), pos, pos + 2);
|
||||
wkr.Decode(bfr, decode_ctx, rdr, src, pos);
|
||||
wkr.Decode(bfr, Bool_.Y, hctx, hpg, rdr, src, pos);
|
||||
pos = rdr.Pos();
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", Err_.Message_gplx_log(e));
|
||||
pos += 2;
|
||||
wkr.Pool__rls();
|
||||
Err err = Err_.cast_or_make(e);
|
||||
if (!err.Logged()) Gfo_usr_dlg_.Instance.Warn_many("", "", Err_.Message_gplx_log(e), "page_url", page_url, "mid", Bry_.Mid_by_len_safe(src, pos, 255));
|
||||
pos += 2; // 2: skip escape and hook
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (add_bgn == -1) add_bgn = pos;
|
||||
if (txt_bgn == -1) txt_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
if (add_bgn != -1) bfr.Add_mid(src, add_bgn, src_len);
|
||||
return bfr.To_bry_and_clear();
|
||||
if (txt_bgn != -1) bfr.Add_mid(src, txt_bgn, src_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ 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.*;
|
||||
public interface Xoh_hzip_wkr {
|
||||
import gplx.xowa.htmls.core.wkrs.*;
|
||||
public interface Xoh_hzip_wkr extends gplx.core.threads.poolables.Gfo_poolable_itm {
|
||||
String Key();
|
||||
int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr parser, byte[] src, int hook_bgn);
|
||||
int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr parser, byte[] src, int hook_bgn);
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.ios.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xow_hzip_mgr {
|
||||
private final Xow_wiki wiki; private final Io_stream_zip_mgr zip_mgr;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_(255);
|
||||
private boolean default_hzip_enabled; private byte default_zip_tid, body_flag;
|
||||
public Xow_hzip_mgr(Xow_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
this.zip_mgr = new Io_stream_zip_mgr();
|
||||
}
|
||||
public Xoh_hzip_mgr Hzip_mgr() {return hzip_mgr;} private final Xoh_hzip_mgr hzip_mgr = new Xoh_hzip_mgr();
|
||||
public Hzip_stat_itm Stat_itm() {return stat_itm;} private final Hzip_stat_itm stat_itm = new Hzip_stat_itm();
|
||||
public byte Body_flag() {return body_flag;}
|
||||
public void Init_by_db(Xow_wiki wiki) {
|
||||
this.Init_by_atrs(wiki.Data__core_mgr().Props().Zip_tid_html(), wiki.Data__core_mgr().Props().Hzip_enabled());
|
||||
}
|
||||
public void Init_by_atrs(byte default_zip_tid, boolean default_hzip_enabled) {
|
||||
this.default_zip_tid = default_zip_tid;
|
||||
this.default_hzip_enabled = default_hzip_enabled;
|
||||
this.body_flag = default_hzip_enabled ? (byte)(default_zip_tid + Zip_tid_cutoff) : default_zip_tid;
|
||||
}
|
||||
public byte[] Write(byte[] page_url, byte storage_flag, byte[] src) {
|
||||
byte zip_tid = default_zip_tid;
|
||||
boolean hzip_enabled = default_hzip_enabled;
|
||||
if (storage_flag != Byte_.Max_value_127) {
|
||||
zip_tid = storage_flag;
|
||||
if (storage_flag > Zip_tid_cutoff) {
|
||||
hzip_enabled = Bool_.Y;
|
||||
zip_tid -= Zip_tid_cutoff;
|
||||
}
|
||||
}
|
||||
if (hzip_enabled) {
|
||||
hzip_mgr.Encode(tmp_bfr, wiki, page_url, src, stat_itm);
|
||||
src = tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
if (zip_tid != Io_stream_.Tid_raw)
|
||||
src = zip_mgr.Zip(zip_tid, src);
|
||||
return src;
|
||||
}
|
||||
public byte[] Parse(byte[] page_url, byte storage_flag, byte[] src) {
|
||||
byte zip_tid = default_zip_tid;
|
||||
boolean hzip_enabled = default_hzip_enabled;
|
||||
if (storage_flag != Byte_.Max_value_127) {
|
||||
zip_tid = storage_flag;
|
||||
if (storage_flag > Zip_tid_cutoff) {
|
||||
hzip_enabled = Bool_.Y;
|
||||
zip_tid -= Zip_tid_cutoff;
|
||||
}
|
||||
}
|
||||
if (zip_tid != Io_stream_.Tid_raw)
|
||||
src = zip_mgr.Unzip(default_zip_tid, src);
|
||||
if (hzip_enabled)
|
||||
src = hzip_mgr.Decode(tmp_bfr, wiki, page_url, src);
|
||||
return src;
|
||||
}
|
||||
private static final byte Zip_tid_cutoff = 7;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips.tests; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_hzip_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final Xoh_hzip_mgr hzip_mgr;
|
||||
private final Hzip_stat_itm stat_itm = new Hzip_stat_itm();
|
||||
public Xoh_hzip_fxt() {
|
||||
Xoa_app_fxt.repo2_(parser_fxt.App(), parser_fxt.Wiki()); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
|
||||
parser_fxt.Wiki().Html__hdump_mgr().Init_by_db(parser_fxt.Wiki());
|
||||
this.hzip_mgr = parser_fxt.Wiki().Html__hdump_mgr().Hzip_mgr().Hzip_mgr();
|
||||
}
|
||||
public Xop_fxt Parser_fxt() {return parser_fxt;} private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
public Xoh_hzip_mgr Hzip_mgr() {return hzip_mgr;}
|
||||
public void Test__bicode(String hzip, String html) {
|
||||
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
|
||||
Test__encode__raw(hzip, html);
|
||||
Test__decode__raw(hzip, html);
|
||||
}
|
||||
public void Test__encode(String hzip, String html) {
|
||||
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
|
||||
Test__encode__raw(hzip, html);
|
||||
}
|
||||
public void Test__decode(String hzip, String html) {
|
||||
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
|
||||
Test__decode__raw(hzip, html);
|
||||
}
|
||||
public void Test__encode__fail(String expd, String html) {
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(html), stat_itm);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
private void Test__encode__raw(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(html), stat_itm);
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
Tfds.Eq_str_lines(hzip, bfr.To_str_and_clear());
|
||||
}
|
||||
private void Test__decode__raw(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
byte[] actl = hzip_mgr.Decode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(hzip));
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
Tfds.Eq_str_lines(html, String_.new_u8(actl));
|
||||
}
|
||||
public static String Escape(String v) {return String_.Replace(v, "~", "");}
|
||||
}
|
||||
@@ -16,17 +16,19 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.brys.fmtrs.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_make_mgr {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255); private final Bry_rdr_old bry_rdr = new Bry_rdr_old(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
private Xoh_cfg_file cfg_file; private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private Xoh_file_html_fmtr__base html_fmtr;
|
||||
private final byte[] root_dir, file_dir; private byte[] file_dir_comm, file_dir_wiki, hiero_img_dir; private final byte[] wiki_domain;
|
||||
private final Bry_rdr parser = new Bry_rdr();
|
||||
private final Xoh_hdoc_wkr__base hdoc_parser = new Xoh_hdoc_wkr__base(new Xoh_hdoc_wkr__make());
|
||||
private final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx();
|
||||
private final Xoh_hdoc_parser make_parser = new Xoh_hdoc_parser(new Xoh_hdoc_wkr__make());
|
||||
public Xoh_make_mgr(Gfo_usr_dlg usr_dlg, Xoa_fsys_mgr fsys_mgr, Url_encoder fsys_encoder, byte[] wiki_domain) {
|
||||
this.usr_dlg = usr_dlg;
|
||||
this.root_dir = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
@@ -37,8 +39,9 @@ public class Xoh_make_mgr {
|
||||
this.wiki_domain = wiki_domain;
|
||||
}
|
||||
public byte[] Parse(byte[] src, Xoh_page hpg, Xow_wiki wiki) {
|
||||
hctx.Init_by_page(wiki, hpg.Url_bry_safe());
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
hdoc_parser.Parse(bfr, wiki, hpg, hpg.Url_bry_safe(), src);
|
||||
make_parser.Parse(bfr, hpg, hctx, src);
|
||||
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
@@ -50,7 +53,7 @@ public class Xoh_make_mgr {
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
Xohd_img_itm__base[] imgs = hpg.Img_itms(); int imgs_len = hpg.Img_itms().length;
|
||||
int pos = 0; int rng_bgn = -1;
|
||||
parser.Ctor_by_page(hpg.Url_bry_safe(), src, src_len);
|
||||
parser.Init_by_page(hpg.Url_bry_safe(), src, src_len);
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
|
||||
|
||||
@@ -16,10 +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; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.htmls.core.wkrs.mkrs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_hdoc_ctx {
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
public void Ctor(Xow_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
private byte[] fsys__file;
|
||||
public byte[] Fsys__root() {return fsys__root;} private byte[] fsys__root;
|
||||
public byte[] Fsys__file__comm() {return fsys__file__comm;} private byte[] fsys__file__comm;
|
||||
public byte[] Fsys__file__wiki() {return fsys__file__wiki;} private byte[] fsys__file__wiki;
|
||||
public byte[] Wiki__domain_bry() {return wiki__domain_bry;} private byte[] wiki__domain_bry;
|
||||
public Xow_ttl_parser Wiki__ttl_parser() {return wiki__ttl_parser;} private Xow_ttl_parser wiki__ttl_parser;
|
||||
public Xoa_file_mgr File__mgr() {return file__mgr;} private final Xoa_file_mgr file__mgr = new Xoa_file_mgr();
|
||||
public Xof_url_bldr File__url_bldr() {return file__url_bldr;} private Xof_url_bldr file__url_bldr = new Xof_url_bldr();
|
||||
public Xoh_hdoc_mkr Mkr() {return mkr;} private Xoh_hdoc_mkr mkr = new Xoh_hdoc_mkr();
|
||||
public byte[] Page__url() {return page__url;} private byte[] page__url;
|
||||
public Hzip_stat_itm Bicode__stat() {return bicode__stat;} private final Hzip_stat_itm bicode__stat = new Hzip_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 void Init_by_app(Xoa_app app) {
|
||||
Xoa_fsys_mgr fsys_mgr = app.Fsys_mgr();
|
||||
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);
|
||||
}
|
||||
public void Init_by_page(Xow_wiki wiki, byte[] page_url) {
|
||||
if (fsys__root == null) Init_by_app(wiki.App()); // LAZY INIT
|
||||
this.wiki__ttl_parser = wiki;
|
||||
this.wiki__domain_bry = wiki.Domain_bry();
|
||||
this.fsys__file__wiki = Bry_.Add(fsys__file, wiki__domain_bry, Byte_ascii.Slash_bry);
|
||||
this.page__url = page_url;
|
||||
this.Clear();
|
||||
}
|
||||
private void Clear() {
|
||||
bicode__stat.Clear();
|
||||
this.lnki__uid = 1; // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,23 +17,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.wkrs.tags.*; import gplx.xowa.htmls.core.wkrs.txts.*; import gplx.xowa.htmls.core.wkrs.escapes.*; import gplx.xowa.htmls.core.wkrs.spaces.*;
|
||||
public class Xoh_hdoc_wkr__base {
|
||||
private final Html_doc_parser hdoc_parser = new Html_doc_parser();
|
||||
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.wkrs.spaces.*;
|
||||
public class Xoh_hdoc_parser {
|
||||
private final Xoh_hdoc_wkr hdoc_wkr;
|
||||
private final Xoh_doc_wkr__tag wkr__tag = new Xoh_doc_wkr__tag();
|
||||
public Xoh_hdoc_wkr__base(Xoh_hdoc_wkr hdoc_wkr) {
|
||||
private final Html_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.hdoc_parser.Reg_txt(new Xoh_txt_parser(hdoc_wkr)).Reg_wkrs
|
||||
( wkr__tag
|
||||
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_parser(hdoc_wkr)
|
||||
, new Xoh_space_parser(hdoc_wkr)
|
||||
);
|
||||
}
|
||||
public void Parse(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] page_url, byte[] src) {
|
||||
public void Parse(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src) {
|
||||
int src_len = src.length;
|
||||
hdoc_wkr.On_new_page(bfr, wiki, hpg, src, 0, src_len);
|
||||
wkr__tag.Ctor(hdoc_wkr, wiki).Init(src, 0, src_len);
|
||||
hdoc_parser.Parse(src, 0, src_len);
|
||||
tag_parser.Init(hctx, src, 0, src_len);
|
||||
hdoc_wkr.On_new_page(bfr, hpg, hctx, src, 0, src_len);
|
||||
hdoc_parser.Parse(hctx.Page__url(), src, 0, src_len);
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,13 @@ package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gpl
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public interface Xoh_hdoc_wkr {
|
||||
Xoh_hdoc_ctx Ctx();
|
||||
void On_new_page(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src, int src_bgn, int src_end);
|
||||
void On_new_page(Bry_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_space (int rng_bgn, int rng_end);
|
||||
void On_hdr (int tag_bgn, int tag_end, int level, int capt_bgn, int capt_end, byte[] anch);
|
||||
void On_lnke (int tag_bgn, int tag_end, byte lnke_type, int autonumber_id, int href_bgn, int href_end);
|
||||
void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser arg);
|
||||
void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser arg);
|
||||
void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg);
|
||||
void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg);
|
||||
void On_img_thm (int rng_bgn, int rng_end);
|
||||
void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg);
|
||||
}
|
||||
|
||||
@@ -16,31 +16,21 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
|
||||
private final Hzip_stat_itm stat_itm = new Hzip_stat_itm();
|
||||
private Bry_bfr bfr; private byte[] src; private int src_end;
|
||||
public Xoh_hdoc_ctx Ctx() {return ctx;} private final Xoh_hdoc_ctx ctx = new Xoh_hdoc_ctx();
|
||||
public void On_new_page(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.src = src; this.src_end = src_end;
|
||||
ctx.Ctor(wiki);
|
||||
private Bry_bfr bfr; private Xoh_hdoc_ctx hctx; private byte[] src; private int src_end;
|
||||
public void On_new_page(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.hctx = hctx; this.src = src; this.src_end = src_end;
|
||||
stat_itm.Clear();
|
||||
}
|
||||
public void On_hdr (int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) {
|
||||
Xoh_hzip_dict_.Wkr__hdr.Encode(bfr, stat_itm, src, rng_bgn, rng_end, level, capt_bgn, capt_end, anch);
|
||||
}
|
||||
public void On_lnke (int rng_bgn, int rng_end, byte lnke_type, int autonumber_id, int href_bgn, int href_end) {
|
||||
Xoh_hzip_dict_.Wkr__lnke.Encode(bfr, stat_itm, src, rng_bgn, rng_end, lnke_type, href_bgn, href_end, autonumber_id);
|
||||
}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {
|
||||
Xoh_hzip_dict_.Wkr__lnki.Encode(bfr, stat_itm, src, arg);
|
||||
}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {
|
||||
Xoh_hzip_dict_.Wkr__img.Encode(bfr, stat_itm, src, arg);
|
||||
}
|
||||
public void On_img_thm (int rng_bgn, int rng_end) {}//wkr__img_thm.Encode(bfr, stat_itm, src, rng_bgn, rng_end);}
|
||||
public void On_escape (int rng_bgn, int rng_end) {Xoh_hzip_dict_.Wkr__escape.Encode(bfr, stat_itm);}
|
||||
public void On_space (int rng_bgn, int rng_end) {Xoh_hzip_dict_.Wkr__space.Encode(bfr, stat_itm, src, src_end, rng_bgn, rng_end);}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
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.Mkr().Escape__hzip().Encode(bfr, stat_itm).Pool__rls();}
|
||||
public void On_space (int rng_bgn, int rng_end) {hctx.Mkr().Space__hzip().Encode(bfr, stat_itm, src, src_end, rng_bgn, rng_end).Pool__rls();}
|
||||
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser arg) {hctx.Mkr().Hdr__hzip().Encode(bfr, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser arg) {hctx.Mkr().Lnke__hzip().Encode(bfr, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {hctx.Mkr().Lnki__hzip().Encode(bfr, hctx, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg) {hctx.Mkr().Thm__hzip().Encode(bfr, this, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {hctx.Mkr().Img__hzip().Encode(bfr, stat_itm, src, arg, Bool_.Y).Pool__rls();}
|
||||
}
|
||||
|
||||
@@ -18,24 +18,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.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 Bry_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_make wkr__img = new Xoh_img_make();
|
||||
private Bry_bfr bfr; private Xoh_page hpg; private byte[] src;
|
||||
public Xoh_hdoc_ctx Ctx() {return ctx;} private final Xoh_hdoc_ctx ctx = new Xoh_hdoc_ctx();
|
||||
public void On_new_page(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.src = src; this.hpg = hpg;
|
||||
ctx.Ctor(wiki);
|
||||
private final Xoh_img_bldr wkr__img = new Xoh_img_bldr();
|
||||
public void On_new_page(Bry_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_space (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_hdr (int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) {
|
||||
wkr__hdr.Make(bfr, hpg, src, rng_bgn, rng_end, level, capt_bgn, capt_end, anch);
|
||||
}
|
||||
public void On_lnke (int rng_bgn, int rng_end, byte lnke_type, int autonumber_id, int href_bgn, int href_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {wkr__img.Make(bfr, hpg, src, arg);}
|
||||
public void On_img_thm (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_escape (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_space (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_lnke (gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser arg) {wkr__hdr.Make(bfr, hpg, src, arg);}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {wkr__img.Make_by_parse(bfr, hpg, hctx, src, arg);}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class Xoh_itm_parser_fxt_base {
|
||||
}
|
||||
public void Exec_parse(String src_str) {
|
||||
this.src = Bry_.new_u8(src_str); this.src_len = src.length;
|
||||
rdr.Ctor_by_page(Xoa_page_.Main_page_bry, src, src_len);
|
||||
rdr.Init_by_page(Xoa_page_.Main_page_bry, src, src_len);
|
||||
Exec_parse_hook(rdr, 0, src_len);
|
||||
}
|
||||
public abstract void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.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;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.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 Bfr_arg val_as_arg;
|
||||
public Bfr_arg__html_atr(byte[] key) {this.atr_bgn = Bld_atr_bgn(key);}
|
||||
public void Clear() {
|
||||
val_type = Type__null;
|
||||
val_as_arg = null;
|
||||
val_as_int = Int_.Min_value;
|
||||
}
|
||||
public Bfr_arg__html_atr Set_by_arg(Bfr_arg v) {val_type = Type__arg; val_as_arg = v; return this;}
|
||||
public Bfr_arg__html_atr Set_by_int(int v) {val_type = Type__int; val_as_int = v; return this;}
|
||||
public void Bfr_arg__clear() {this.Clear();}
|
||||
public boolean Bfr_arg__exists() {
|
||||
switch (val_type) {
|
||||
case Type__null: return false;
|
||||
case Type__arg: return val_as_arg.Bfr_arg__exists();
|
||||
case Type__int: return val_as_int != Int_.Min_value;
|
||||
default: throw Err_.new_unhandled(val_type);
|
||||
}
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
if (!Bfr_arg__exists()) return;
|
||||
bfr.Add(atr_bgn);
|
||||
switch (val_type) {
|
||||
case Type__arg: val_as_arg.Bfr_arg__add(bfr); break;
|
||||
case Type__int: bfr.Add_int_variable(val_as_int); break;
|
||||
}
|
||||
bfr.Add_byte_quote();
|
||||
}
|
||||
public static byte[] Bld_atr_bgn(byte[] key) {return Bry_.Add(Byte_ascii.Space_bry, key, Byte_ascii.Eq_bry, Byte_ascii.Quote_bry);} // ' key="'
|
||||
private static final int Type__null = 0, Type__arg = 1, Type__int = 2;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.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);
|
||||
}
|
||||
}
|
||||
@@ -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.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);
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,21 @@ 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.core.brys.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_escape_hzip implements Xoh_hzip_wkr {
|
||||
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 {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__escape;}
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm) {
|
||||
public Xoh_escape_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm) {
|
||||
stat_itm.Escape_add_one();
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__escape);
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
return rdr.Pos();
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_escape_hzip rv = new Xoh_escape_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
||||
|
||||
@@ -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.escapes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
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() {
|
||||
|
||||
@@ -22,8 +22,7 @@ public class Xoh_escape_parser implements Html_doc_wkr {
|
||||
private final Xoh_hdoc_wkr wkr;
|
||||
public Xoh_escape_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
|
||||
public byte[] Hook() {return Xoh_hzip_dict_.Escape_bry;}
|
||||
public void Init(byte[] src, int src_bgn, int src_end) {}
|
||||
public int Parse(int pos) {
|
||||
public int Parse(byte[] src, int src_bgn, int src_end, int pos) {
|
||||
int rv = pos + 1;
|
||||
wkr.On_escape(pos, rv);
|
||||
return rv;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
public class Xoh_gly_grp_cls_ {
|
||||
public static final byte[]
|
||||
Bry__traditional = Bry_.new_a7("traditional")
|
||||
, Bry__packed = Bry_.new_a7("packed")
|
||||
;
|
||||
// public static final
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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.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");
|
||||
}
|
||||
@@ -16,19 +16,21 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_hdr_hzip implements Xoh_hzip_wkr {
|
||||
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 String Key() {return Xoh_hzip_dict_.Key__hdr;}
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) {
|
||||
public Xoh_hdr_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_hdr_parser arg) {
|
||||
int level = arg.Hdr_level();
|
||||
stat_itm.Hdr_add(level);
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__hdr); // add hook
|
||||
bfr.Add_int_digits(1, level); // add level; EX: 2 in <h2>
|
||||
bfr.Add_mid(src, capt_bgn, capt_end).Add_byte(Xoh_hzip_dict_.Escape); // add caption
|
||||
if (anch != null) bfr.Add(anch); // add anchor
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__hdr); // add hook
|
||||
bfr.Add_int_digits(1, level); // add level; EX: 2 in <h2>
|
||||
bfr.Add_mid(src, arg.Capt_bgn(), arg.Capt_end()).Add_byte(Xoh_hzip_dict_.Escape); // add caption
|
||||
bfr.Add_safe(arg.Anch_bry()); // add anchor
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
byte level = rdr.Read_byte();
|
||||
int capt_bgn = rdr.Pos();
|
||||
int capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
@@ -53,4 +55,8 @@ public class Xoh_hdr_hzip implements Xoh_hzip_wkr {
|
||||
, Bry__hdr__2 = Bry_.new_a7("\">")
|
||||
, Bry__hdr__3 = Bry_.new_a7("</span>\n</h")
|
||||
;
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hdr_hzip rv = new Xoh_hdr_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
||||
|
||||
@@ -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.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_hdr_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Same() {
|
||||
|
||||
@@ -19,13 +19,17 @@ package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; impor
|
||||
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, int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) {
|
||||
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.Rng_bgn(), rng_end = arg.Rng_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, capt_bgn, capt_end);
|
||||
byte[] capt = Bry_.Mid(src, arg.Capt_bgn(), arg.Capt_end());
|
||||
byte[] anch = arg.Anch_bry();
|
||||
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);
|
||||
|
||||
@@ -18,17 +18,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_hdr_parser {
|
||||
public int Parse(Xoh_hdoc_wkr wkr, Html_tag_rdr rdr, byte[] src, int hdr_name_id, int rng_bgn, Html_tag span) {// <h2><span class='mw-headline' id='A_1'>A 1</span></h2>
|
||||
Html_atr anch_atr = span.Atrs__get_by(Html_atr_.Bry__id);
|
||||
// gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public int Hdr_level() {return hdr_level;} private int hdr_level;
|
||||
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
|
||||
public int Capt_end() {return capt_end;} private int capt_end;
|
||||
public byte[] Anch_bry() {return anch_bry;} private byte[] anch_bry;
|
||||
public int Parse(Xoh_hdoc_wkr wkr, byte[] src, Html_tag_rdr rdr, int hdr_level, int rng_bgn, Html_tag span) {// <h2><span class='mw-headline' id='A_1'>A 1</span></h2>
|
||||
this.rng_bgn = rng_bgn; this.hdr_level = hdr_level;
|
||||
Html_atr anch_atr = span.Atrs__get_by_or_fail(Html_atr_.Bry__id);
|
||||
int anch_bgn = anch_atr.Val_bgn(), anch_end = anch_atr.Val_end();
|
||||
int capt_bgn = span.Src_end();
|
||||
rdr.Tag__move_fwd_tail(hdr_name_id); // find </h2> not </span> since <span> can be nested, but <h2> cannot
|
||||
int capt_end = rdr.Tag__peek_bwd_tail(Html_tag_.Id__span).Src_bgn(); // get </span> before </h2>
|
||||
byte[] anch = null;
|
||||
this.capt_bgn = span.Src_end();
|
||||
rdr.Tag__move_fwd_tail(hdr_level); // find </h2> not </span> since <span> can be nested, but <h2> cannot
|
||||
this.capt_end = rdr.Tag__peek_bwd_tail(Html_tag_.Id__span).Src_bgn(); // get </span> before </h2>
|
||||
this.anch_bry = null;
|
||||
if (!Bry_.Match_w_swap(src, capt_bgn, capt_end, src, anch_bgn, anch_end, Byte_ascii.Space, Byte_ascii.Underline))
|
||||
anch = Bry_.Mid(src, anch_bgn, anch_end); // anch is different than capt; occurs with html and dupe-anchors; EX: "==<i>A</i>==" -> id='A'
|
||||
int rng_end = rdr.Pos();
|
||||
wkr.On_hdr(rng_bgn, rng_end, hdr_name_id, capt_bgn, capt_end, anch);
|
||||
this.anch_bry = Bry_.Mid(src, anch_bgn, anch_end); // anch is different than capt; occurs with html and dupe-anchors; EX: "==<i>A</i>==" -> id='A'
|
||||
this.rng_end = rdr.Pos();
|
||||
wkr.On_hdr(this);
|
||||
return rng_end;
|
||||
}
|
||||
public static final byte[] Bry__class__mw_headline = Bry_.new_a7("mw-headline");
|
||||
}
|
||||
|
||||
@@ -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.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_parser().File_ttl_bry(), arg.Img_xoimg_parser()
|
||||
, arg.Anch_href_parser().Atr(), arg.Anch_cls_parser().Atr(), arg.Anch_title_atr()
|
||||
, arg.Img_w(), arg.Img_h(), arg.Img_src_parser().Atr(), arg.Img_cls_parser().Atr(), arg.Img_alt_atr());
|
||||
wtr.Bfr_arg__add(bfr);
|
||||
}
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, byte[] lnki_ttl, Xoh_img_xoimg_parser img_xoimg
|
||||
, Bfr_arg anch_href, Bfr_arg anch_cls, Bfr_arg anch_ttl
|
||||
, int img_w, int img_h, Bfr_arg img_src, Bfr_arg img_cls, Bfr_arg img_alt) {
|
||||
wtr.Clear();
|
||||
this.fsdb_itm = hpg.Img_mgr().Make_img();
|
||||
if (img_xoimg.Val_exists()) {
|
||||
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);
|
||||
}
|
||||
else if (img_w != -1) {
|
||||
wtr.Img_w_(img_w).Img_h_(img_h).Img_src_(img_src);
|
||||
}
|
||||
wtr.Anch_href_(anch_href).Anch_cls_(anch_cls).Anch_title_(anch_ttl);
|
||||
wtr.Img_id_(Xoh_img_mgr.Bry__html_uid, fsdb_itm.Html_uid()).Img_alt_(img_alt).Img_cls_(img_cls);
|
||||
}
|
||||
}
|
||||
@@ -16,23 +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.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
public class Xoh_img_hzip implements Xoh_hzip_wkr {
|
||||
public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
private final int[] flag_ary;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_
|
||||
( 1, 1, 1, 1
|
||||
, 1, 1, 1, 1
|
||||
, 1, 1, 1, 2
|
||||
, 2);
|
||||
( 1, 1, 1, 1, 1, 1, 1, 1
|
||||
, 1, 1, 1, 2, 2);
|
||||
public Xoh_img_hzip() {
|
||||
this.flag_ary = flag_bldr.Val_ary();
|
||||
}
|
||||
public String Key() {return Xoh_hzip_dict_.Key__img;}
|
||||
public void Encode( Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_img_parser arg) {
|
||||
public Xoh_img_bldr Bldr() {return bldr__img;} private Xoh_img_bldr bldr__img = new Xoh_img_bldr();
|
||||
public Xoh_img_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_img_parser arg, boolean write_hdr) {
|
||||
// img_map: <img id="xowa_file_img_100" alt="" src="file:///J:/xowa/file/commons.wikimedia.org/orig/b/8/a/7/Solar_System_Template_Final.png" width="666" height="36" usemap="#imagemap_1_1">
|
||||
Xoh_anch_href_parser anch_href = arg.Anch_href_parser();
|
||||
Html_atr anch_title = arg.Anch_title_atr();
|
||||
@@ -56,13 +55,13 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr {
|
||||
flag_ary[10] = img_src.File_page_exists() ? 1 : 0;
|
||||
flag_ary[11] = arg.Anch_cls_parser().Tid();
|
||||
flag_ary[12] = img_cls.Cls_tid();
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__img);
|
||||
if (write_hdr) bfr.Add(Xoh_hzip_dict_.Bry__img);
|
||||
Xoh_hzip_int_.Encode(3, bfr, flag_bldr.Encode());
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_w());
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_h());
|
||||
bfr.Add(anch_href_ttl.Page_db()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (!anch_href_is_file) {
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, anch_href_ttl);
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, anch_href_ttl.Ns().Id());
|
||||
bfr.Add_mid(src, img_src.File_ttl_bgn(), img_src.File_ttl_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
if (arg.File_w__diff__img_w()) Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_w());
|
||||
@@ -72,8 +71,19 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr {
|
||||
if (anch_title.Val_exists()) bfr.Add_mid(src, anch_title.Val_bgn(), anch_title.Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img_alt__diff__anch_title) bfr.Add_mid(src, arg.Img_alt_atr().Val_bgn(), arg.Img_alt_atr().Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img_cls.Other_exists()) bfr.Add_mid(src, img_cls.Other_bgn(), img_cls.Other_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
private final Xoh_img_xoimg_parser xoimg_parser = new Xoh_img_xoimg_parser();
|
||||
public Bfr_arg__href Anch_href_arg() {return anch_href_arg;} private final Bfr_arg__href anch_href_arg = new Bfr_arg__href();
|
||||
private final Bry_obj_ref
|
||||
anch_cls_mid = Bry_obj_ref.New_empty()
|
||||
, anch_title_mid = Bry_obj_ref.New_empty()
|
||||
, 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 int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
// decode rdr
|
||||
int flag = rdr.Read_int_by_base85(3);
|
||||
flag_bldr.Decode(flag);
|
||||
int img_w = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
|
||||
@@ -96,14 +106,16 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr {
|
||||
}
|
||||
int file_time = -1; int file_page = -1;
|
||||
int img_xoimg_bgn = -1; int img_xoimg_end = -1;
|
||||
xoimg_parser.Clear();
|
||||
if (img_xoimg_exists) {
|
||||
img_xoimg_bgn = rdr.Pos();
|
||||
img_xoimg_end = rdr.Find_fwd_lr();
|
||||
xoimg_parser.Parse(rdr, src, img_xoimg_bgn, img_xoimg_end);
|
||||
}
|
||||
int anch_title_bgn = -1, anch_title_end = -1;
|
||||
if (anch_title_exists) {
|
||||
anch_title_bgn = rdr.Pos();
|
||||
anch_title_end = rdr.Find_fwd_lr();
|
||||
anch_title_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
int img_alt_bgn = -1, img_alt_end = -1;
|
||||
if (anch_title_exists) {
|
||||
@@ -117,52 +129,38 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr {
|
||||
byte[] img_cls_other = Bry_.Empty;
|
||||
if (img_cls_other_exists)
|
||||
img_cls_other = Bry_.Mid(src, rdr.Pos(), rdr.Find_fwd_lr());
|
||||
byte[] img_cls_bry = Xoh_img_cls_.To_html(img_cls, img_cls_other);
|
||||
byte[] anch_cls_bry = Xoh_anch_cls_.To_html(anch_cls);
|
||||
int rv = rdr.Move_to(rdr.Pos());
|
||||
|
||||
bfr.Add(Html_bldr_.Bry__a_lhs_w_href); // '<a href="'
|
||||
if (anch_href_is_file) { // 99% of cases; href='/wiki/File:A.png'
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // '/wiki/'
|
||||
bfr.Add(Xow_ns_.Bry__file).Add_byte_colon(); // 'File:'
|
||||
bfr.Add(page_db); // 'A.png'
|
||||
}
|
||||
// transform values
|
||||
if (anch_href_is_file)
|
||||
anch_href_arg.Set_by_file(page_db);
|
||||
else {
|
||||
if (anch_href_has_site) {
|
||||
}
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // '/wiki/'
|
||||
Xoa_ttl anch_href_ttl = ctx.Ttl_parser().Ttl_parse(anch_href_ns, page_db);
|
||||
bfr.Add(anch_href_ttl.Full_db());
|
||||
Xoa_ttl anch_href_ttl = hctx.Wiki__ttl_parser().Ttl_parse(anch_href_ns, page_db);
|
||||
anch_href_arg.Set_by_page(anch_href_ttl.Full_db());
|
||||
page_db = anch_href_ttl_bry;
|
||||
}
|
||||
Xof_url_bldr url_bldr = ctx.Url_bldr();
|
||||
url_bldr.Init_by_root(repo_is_commons ? ctx.Dir__file__comm() : ctx.Dir__file__wiki(), Byte_ascii.Slash, false, false, 2);
|
||||
// NOTE: src must go underneath ttl
|
||||
Xof_url_bldr url_bldr = hctx.File__url_bldr();
|
||||
url_bldr.Init_by_root(repo_is_commons ? hctx.Fsys__file__comm() : hctx.Fsys__file__wiki(), Byte_ascii.Slash, false, false, Md5_depth);
|
||||
url_bldr.Init_by_itm(file_is_orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, page_db, Xof_file_wkr_.Md5(page_db), Xof_ext_.new_by_ttl_(page_db), img_w, file_time, file_page);
|
||||
byte[] img_src = url_bldr.Xto_bry();
|
||||
|
||||
bfr.Add(anch_cls_bry); // '" class="image'
|
||||
if (anch_title_exists) {
|
||||
bfr.Add(Html_bldr_.Bry__title__nth); // '" title="'
|
||||
bfr.Add_mid(src, anch_title_bgn, anch_title_end); // 'abc'
|
||||
}
|
||||
bfr.Add(Html_bldr_.Bry__lhs_end_head_w_quote); // '">'
|
||||
bfr.Add(Html_bldr_.Bry__img_lhs_w_alt); // '<img alt="'
|
||||
if (anch_title_exists || img_alt__diff__anch_title)
|
||||
bfr.Add_mid(src, img_alt_bgn, img_alt_end); // 'abc'
|
||||
if (img_xoimg_exists) {
|
||||
bfr.Add(Xoh_img_xoimg_parser.Bry__html);
|
||||
bfr.Add_mid(src, img_xoimg_bgn, img_xoimg_end); // '1|220|110...'
|
||||
}
|
||||
bfr.Add(Html_bldr_.Bry__src__nth); // '" src="'
|
||||
bfr.Add(img_src); // 'file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png'
|
||||
bfr.Add(Html_bldr_.Bry__width__nth); // '" width="'
|
||||
bfr.Add_int_variable(img_w); // '220'
|
||||
bfr.Add(Html_bldr_.Bry__height__nth); // '" height="'
|
||||
bfr.Add_int_variable(img_h).Add_byte_quote(); // '110"'
|
||||
bfr.Add(img_cls_bry); // ' class="thumbimage"'
|
||||
bfr.Add(Html_bldr_.Bry__lhs_end_inline); // '/>
|
||||
bfr.Add(Html_bldr_.Bry__a_rhs); // </a>
|
||||
anch_cls_mid.Val_(Xoh_anch_cls_.To_val(anch_cls));
|
||||
anch_title_mid.Mid_(src, anch_title_bgn, anch_title_end);
|
||||
img_alt_mid.Mid_(src, img_alt_bgn, img_alt_end);
|
||||
img_src_mid.Val_(img_src);
|
||||
img_cls_mid.Val_(Xoh_img_cls_.To_val(img_cls, img_cls_other));
|
||||
|
||||
rdr.Move_to(rdr.Src_end());
|
||||
return rdr.Pos();
|
||||
bldr__img.Make(bfr, hpg, hctx, src, page_db, xoimg_parser, anch_href_arg, anch_cls_mid, anch_title_mid, img_w, img_h, img_src_mid, img_cls_mid, img_alt_mid);
|
||||
if (write_to_bfr) bldr__img.Wtr().Bfr_arg__add(bfr);
|
||||
|
||||
return rv;
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_hzip rv = new Xoh_img_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
public static int Md5_depth = 2;
|
||||
}
|
||||
|
||||
@@ -16,13 +16,14 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
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();
|
||||
@Test public void Basic() { // [[File:A.png|border|class=other|220px|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%$+(#T\";A.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, Xoh_img_html__dump__tst.Html__basic
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,20 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_img_hzip__view__tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Basic__border__class__caption() { // [[File:A.png|border|class=other|220px|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!rC#T\";A.png~abc~other~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc'><img alt='abc' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' class='thumbborder other'/></a>"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_0' alt='abc' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' class='thumbborder other'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link() { // [[File:A.png|link=B]]
|
||||
fxt.Test__bicode
|
||||
( "~%!H.#T\";B~#A.png~B~A.png~"
|
||||
, "<a href='/wiki/B' title='B'><img alt='A.png' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'/></a>"
|
||||
, "<a href='/wiki/B' title='B'><img id='xoimg_0' alt='A.png' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'></a>"
|
||||
, "<a href='/wiki/B' title='B'><img id='xoimg_0' alt='A.png' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'></a>"
|
||||
);
|
||||
}
|
||||
// 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>
|
||||
|
||||
@@ -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.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_img_make {
|
||||
private final Xoa_file_mgr file_mgr = new Xoa_file_mgr();
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, byte[] src, Xoh_img_parser arg) {
|
||||
Xoh_img_xoimg_parser img_xoimg = arg.Img_xoimg_parser();
|
||||
Xoh_img_src_parser img_src = arg.Img_src_parser();
|
||||
Xof_fsdb_itm fsdb_itm = hpg.Img_mgr().Make_img();
|
||||
boolean html_data_exists = false;
|
||||
if (img_xoimg.Val_exists()) { // data-xoimg exists; use it
|
||||
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), img_src.File_ttl_bry(), img_xoimg.Lnki_type(), img_xoimg.Lnki_upright(), img_xoimg.Lnki_w(), img_xoimg.Lnki_h(), img_xoimg.Lnki_time(), img_xoimg.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
|
||||
html_data_exists = file_mgr.Check_cache(fsdb_itm);
|
||||
}
|
||||
else if (arg.Img_w_exists()) { // width exists; use it
|
||||
// fsdb_itm.Init_by_hdump(img_src.Repo_is_commons(), img_src.File_ttl_bry(), arg.Img_w(), img_src.File_time(), img_src.File_page());
|
||||
html_data_exists = true;
|
||||
}
|
||||
Write_html(bfr, src, arg, fsdb_itm, html_data_exists);
|
||||
}
|
||||
private void Write_html(Bry_bfr bfr, byte[] src, Xoh_img_parser arg, Xof_fsdb_itm fsdb_itm, boolean html_data_exists) {
|
||||
// html_data_exists = n : "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_1' alt='abc' src=''/></a>"
|
||||
bfr.Add_mid(src, arg.Anch_tag_bgn(), arg.Anch_tag_end()); // '<a href="/wiki/File:A.png" class="image" title="abc">'
|
||||
bfr.Add(Html_bldr_.Bry__img_lhs); // '<img'
|
||||
bfr.Add(Html_bldr_.Bry__id__1st); // ' id="'
|
||||
bfr.Add(Xoh_img_mgr.Bry__html_uid); // 'xoimg_'
|
||||
bfr.Add_int_variable(fsdb_itm.Html_uid()); // '123'
|
||||
bfr.Add(Html_bldr_.Bry__alt__nth); // '" alt="'
|
||||
arg.Img_alt_atr().Html__add(bfr); // 'abc'
|
||||
bfr.Add(Html_bldr_.Bry__src__nth); // '" src="'
|
||||
bfr.Add(Html_bldr_.Bry__lhs_end_inline_w_quote); // '"/>'
|
||||
bfr.Add(Html_bldr_.Bry__a_rhs); // '</a>'
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,8 @@ public class Xoh_img_make__dump__tst {
|
||||
@Before public void Init() {fxt.Clear();}
|
||||
@Test public void Html_exists__n() {
|
||||
String
|
||||
orig = "<a href='/wiki/File:A.png' class='image' title='abc'><img alt='abc' data-xoimg='0|220|110|0.5|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'/></a>"
|
||||
, expd = "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_0' alt='abc' src=''/></a>"
|
||||
orig = "<a href='/wiki/File:A.png' class='image' title='abc'><img alt='abc' data-xoimg='0|220|110|0.5|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'></a>"
|
||||
, expd = "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_0' alt='abc'></a>"
|
||||
;
|
||||
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)
|
||||
|
||||
@@ -37,23 +37,22 @@ public class Xoh_img_parser {
|
||||
public boolean Img_w_exists() {return img_w != -1;}
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public boolean File_w__diff__img_w() {return img_src_parser.File_w() != img_w;}
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_tag) {
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_tag) {
|
||||
// "<a href='/wiki/File:A.png' class='image'><img alt='' src='file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png' width='220' height='110' class='thumbimage'></a>"
|
||||
this.src = src; this.anch_tag_bgn = anch_tag.Src_bgn(); this.anch_tag_end = anch_tag.Src_end();
|
||||
this.rng_bgn = anch_tag_bgn; // <a
|
||||
this.anch_title_atr = anch_tag.Atrs__get_by_or_empty(Html_atr_.Bry__title); // title='abc'
|
||||
anch_cls_parser.Parse(tag_rdr.Rdr(), src, anch_tag); // class='image'
|
||||
anch_href_parser.Parse(tag_rdr.Rdr(), hdoc_wkr.Ctx().Wiki(), anch_tag); // href='/wiki/File:A.png'
|
||||
Html_tag img_tag = tag_rdr.Tag__move_fwd_head(Html_tag_.Id__img); // <img>
|
||||
img_xoimg_parser.Parse(tag_rdr.Rdr(), src, img_tag);
|
||||
anch_href_parser.Parse(tag_rdr.Rdr(), hctx.Wiki__ttl_parser(), anch_tag); // href='/wiki/File:A.png'
|
||||
Html_tag img_tag = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__img); // <img>
|
||||
img_xoimg_parser.Parse(tag_rdr.Rdr(), src, img_tag); // data-xoimg='...'
|
||||
this.img_w = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__width, Xof_img_size.Size__neg1); // width='220'
|
||||
this.img_h = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__height, Xof_img_size.Size__neg1); // height='110'
|
||||
this.img_alt_atr = img_tag.Atrs__get_by_or_empty(Html_atr_.Bry__alt); // alt='File:A.png'
|
||||
img_cls_parser.Parse(tag_rdr.Rdr(), src, img_tag); // class='thumbborder'
|
||||
img_src_parser.Parse(tag_rdr.Rdr(), hdoc_wkr.Ctx().Wiki().Domain_bry(), img_tag); // src='...'
|
||||
img_src_parser.Parse(tag_rdr.Rdr(), hctx.Wiki__domain_bry(), img_tag); // src='...'
|
||||
Html_tag anch_tail_tag = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
|
||||
this.rng_end = anch_tail_tag.Src_end();
|
||||
hdoc_wkr.On_img(this);
|
||||
return rng_end;
|
||||
}
|
||||
public static final byte[]
|
||||
|
||||
65
400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_wtr.java
Normal file
65
400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_wtr.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.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_cls = new Bfr_arg__html_atr(Html_atr_.Bry__class)
|
||||
, anch_title = new Bfr_arg__html_atr(Html_atr_.Bry__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();
|
||||
public Xoh_img_wtr() {
|
||||
arg_ary = new Bfr_arg[]
|
||||
{ indent, anch_href, anch_cls, anch_title
|
||||
, img_id, img_xoimg, img_alt, img_src, img_w, img_h, img_cls
|
||||
};
|
||||
}
|
||||
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_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 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_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_alt_(Bfr_arg v) {img_alt.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Clear() {
|
||||
for (Bfr_arg arg : arg_ary)
|
||||
arg.Bfr_arg__clear();
|
||||
return this;
|
||||
}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, (Object[])arg_ary);
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_
|
||||
( "~{indent}<a~{anch_href}~{anch_cls}~{anch_title}><img~{img_id}~{img_alt}~{img_xoimg}~{img_src}~{img_w}~{img_h}~{img_cls}></a>"
|
||||
, "indent", "anch_href", "anch_cls", "anch_title", "img_id", "img_xoimg", "img_alt", "img_src", "img_w", "img_h", "img_cls");
|
||||
}
|
||||
@@ -42,4 +42,11 @@ public class Xoh_anch_cls_ {
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static byte[] To_val(int tid) {
|
||||
switch (tid) {
|
||||
case Xoh_anch_cls_.Tid__none: return Bry_.Empty;
|
||||
case Xoh_anch_cls_.Tid__image: return Bry__image;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,10 @@ import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_anch_cls_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public Html_atr Atr() {return atr;} private Html_atr atr;
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='image'
|
||||
Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) {
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='image'
|
||||
int src_bgn = atr.Val_bgn(); int src_end = atr.Val_end();
|
||||
if (src_bgn == -1)
|
||||
tid = Xoh_anch_cls_.Tid__none;
|
||||
else {
|
||||
|
||||
@@ -54,4 +54,19 @@ public class Xoh_img_cls_ {
|
||||
}
|
||||
return Bry_.Add(Bry__html_class, cls, other_0, other_1, Byte_ascii.Quote_bry);
|
||||
}
|
||||
public static byte[] To_val(int tid, byte[] other) {
|
||||
boolean other_is_empty = Bry_.Len_eq_0(other);
|
||||
if (tid == Xoh_img_cls_.Tid__none && other_is_empty) return Bry_.Empty;
|
||||
byte[] cls = null;
|
||||
switch (tid) {
|
||||
case Xoh_img_cls_.Tid__thumbimage: cls = Bry__thumbimage; break;
|
||||
case Xoh_img_cls_.Tid__thumbborder: cls = Bry__thumbborder; break;
|
||||
}
|
||||
byte[] other_0 = Bry_.Empty, other_1 = Bry_.Empty;
|
||||
if (!other_is_empty) {
|
||||
if (cls != null) other_0 = Byte_ascii.Space_bry;
|
||||
other_1 = other;
|
||||
}
|
||||
return Bry_.Add(cls, other_0, other_1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,12 @@ public class Xoh_img_cls_parser {
|
||||
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_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='thumbborder'
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='thumbborder'
|
||||
Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) {
|
||||
private void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) {
|
||||
if (src_bgn == -1) {
|
||||
this.cls_tid = Xoh_img_cls_.Tid__none;
|
||||
this.other_bgn = this.other_end = -1;
|
||||
|
||||
@@ -38,8 +38,9 @@ public class Xoh_img_src_parser implements Xoh_itm_parser {
|
||||
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;
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] domain_bry, Html_tag tag) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__src);
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__src);
|
||||
if (!atr.Val_exists()) return;
|
||||
Parse(owner_rdr, domain_bry, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
@@ -55,7 +56,7 @@ public class Xoh_img_src_parser implements Xoh_itm_parser {
|
||||
if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) rdr.Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end));
|
||||
}
|
||||
file_is_orig = rdr.Chk(trie) == Tid__orig; // check if 'orig/' or 'thumb/'
|
||||
file_ttl_bgn = rdr.Move_by(4); // 8 for 4 levels of md5; EX: "0/1/2/3/"
|
||||
file_ttl_bgn = Skip_md5(); // skip md5; EX: "0/1/2/3/"
|
||||
if (file_is_orig)
|
||||
file_ttl_end = rdr.Src_end();
|
||||
else {
|
||||
@@ -68,6 +69,21 @@ public class Xoh_img_src_parser implements Xoh_itm_parser {
|
||||
file_page = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px-5.png"
|
||||
}
|
||||
}
|
||||
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/"
|
||||
&& src[pos + 1] == Byte_ascii.Slash) { // pos is slash; EX: "7/0/"
|
||||
pos += 2;
|
||||
continue;
|
||||
}
|
||||
else { // pos is not slash; title done
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rdr.Move_to(pos);
|
||||
}
|
||||
private static final byte[] Bry__file = Bry_.new_a7("/file/"), Bry__orig = Bry_.new_a7("orig/"), Bry__thumb = Bry_.new_a7("thumb/");
|
||||
private static final byte Tid__orig = 1, Tid__thumb = 2;
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.cs().Add_bry_byte(Bry__orig, Tid__orig).Add_bry_byte(Bry__thumb, Tid__thumb);
|
||||
|
||||
@@ -26,6 +26,9 @@ public class Xoh_img_src_parser_tst {
|
||||
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px@5.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, 5, -1);
|
||||
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px-5.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, -1, 5);
|
||||
}
|
||||
@Test public void Md5_depth_4() {
|
||||
fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/1/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1);
|
||||
}
|
||||
@Test public void Fail__orig_mode() {
|
||||
fxt.Test__parse__fail("file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png", "failed trie check: mid='fail/7/0/A.png' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png'");
|
||||
}
|
||||
|
||||
@@ -29,14 +29,16 @@ public class Xoh_img_xoimg_parser {
|
||||
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
|
||||
public double Lnki_time() {return lnki_time;} private double lnki_time;
|
||||
public int Lnki_page() {return lnki_page;} private int lnki_page;
|
||||
public void Clear() {
|
||||
val_bgn = val_end = -1;
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Bry__name);
|
||||
Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) {
|
||||
if (src_bgn == -1) {
|
||||
val_bgn = val_end = -1;
|
||||
}
|
||||
if (src_bgn == -1)
|
||||
this.Clear();
|
||||
else {
|
||||
rdr.Init_by_sub(owner_rdr, "img.xoimg", src_bgn, src_end).Dflt_dlm_(Byte_ascii.Pipe);
|
||||
this.val_bgn = src_bgn;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
//namespace gplx.xowa.htmls.core.hzips.wkrs {
|
||||
// using gplx.core.btries;
|
||||
// using gplx.xowa.htmls.core.hzips.stats;
|
||||
// using gplx.xowa.htmls.core.hzips;
|
||||
// public class Xoh_hzip_href {
|
||||
// public void Save(Bry_bfr bfr, Hzip_stat_itm stats, byte[] src, int src_len, int bgn, int pos, byte bgn_quote) {
|
||||
//// // ignore anchors; EX: "#a"
|
||||
|
||||
@@ -16,27 +16,29 @@ 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.xowa.wikis.ttls.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_lnke_hzip implements Xoh_hzip_wkr {
|
||||
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 String Key() {return Xoh_hzip_dict_.Key__lnke;}
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int rng_bgn, int rng_end, byte lnke_type, int href_bgn, int href_end, int lnke_id) {
|
||||
public Xoh_lnke_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_lnke_parser arg) {
|
||||
byte lnke_type = arg.Lnke_type();
|
||||
switch (lnke_type) {
|
||||
case Xoh_lnke_dict_.Type__free: stat_itm.Lnke_txt_add();break;
|
||||
case Xoh_lnke_dict_.Type__text: stat_itm.Lnke_brk_text_y_add(); break;
|
||||
case Xoh_lnke_dict_.Type__auto: stat_itm.Lnke_brk_text_n_add(); break;
|
||||
}
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__lnke); // add hook
|
||||
bfr.Add_byte(lnke_type); // add type
|
||||
bfr.Add_mid(src, href_bgn, href_end); // add href
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__lnke); // add hook
|
||||
bfr.Add_byte(lnke_type); // add type
|
||||
bfr.Add_mid(src, arg.Href_bgn(), arg.Href_end()); // add href
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (lnke_type == Xoh_lnke_dict_.Type__auto)
|
||||
Xoh_hzip_int_.Encode(1, bfr, lnke_id);
|
||||
Xoh_hzip_int_.Encode(1, bfr, arg.Autonumber_id());
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
byte lnke_type = rdr.Read_byte();
|
||||
int href_bgn = rdr.Pos();
|
||||
int href_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
int href_end = rdr.Find_fwd_lr();
|
||||
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
|
||||
bfr.Add_mid(src, href_bgn, href_end);
|
||||
bfr.Add(Xoh_lnke_dict_.Html__atr__0).Add(Xoh_lnke_dict_.To_html_class(lnke_type)).Add(Xoh_lnke_dict_.Html__rhs_end);
|
||||
@@ -54,4 +56,8 @@ public class Xoh_lnke_hzip implements Xoh_hzip_wkr {
|
||||
}
|
||||
return rdr.Pos();
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_lnke_hzip rv = new Xoh_lnke_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
||||
|
||||
@@ -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.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_lnke_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Free() {
|
||||
|
||||
@@ -18,26 +18,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*;
|
||||
public class Xoh_lnke_parser {
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, Html_tag anch) {// <a rel="nofollow" class="external autonumber_id" href="http://a.org">[1]</a>
|
||||
int rng_bgn = anch.Src_bgn(), rng_end = anch.Src_end();
|
||||
Html_atr href_atr = anch.Atrs__get_by(Html_atr_.Bry__href);
|
||||
int href_bgn = href_atr.Val_bgn(), href_end = href_atr.Val_end();
|
||||
byte lnke_type = anch.Atrs__cls_find_1st(Xoh_lnke_dict_.Hash);
|
||||
int autonumber_id = 0;
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public int Href_bgn() {return href_bgn;} private int href_bgn;
|
||||
public int Href_end() {return href_end;} private int href_end;
|
||||
public int Autonumber_id() {return autonumber_id;} private int autonumber_id;
|
||||
public byte Lnke_type() {return lnke_type;} private byte lnke_type;
|
||||
private void Clear() {
|
||||
this.lnke_type = Byte_ascii.Max_7_bit;
|
||||
this.rng_bgn = this.rng_end = this.href_bgn = href_end = -1;
|
||||
this.autonumber_id = 0;
|
||||
}
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, Html_tag anch) {// <a rel="nofollow" class="external autonumber" href="http://a.org">[1]</a>
|
||||
this.Clear();
|
||||
this.rng_bgn = anch.Src_bgn(); this.rng_end = anch.Src_end();
|
||||
Html_atr href_atr = anch.Atrs__get_by_or_fail(Html_atr_.Bry__href);
|
||||
this.href_bgn = href_atr.Val_bgn(); this.href_end = href_atr.Val_end();
|
||||
this.lnke_type = anch.Atrs__cls_find_or_fail(Xoh_lnke_dict_.Hash);
|
||||
switch (lnke_type) {
|
||||
case Xoh_lnke_dict_.Type__free:
|
||||
rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that free is not recursive; EX: "https://a.org"
|
||||
this.rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that free is not recursive; EX: "https://a.org"
|
||||
break;
|
||||
case Xoh_lnke_dict_.Type__text:
|
||||
break;
|
||||
case Xoh_lnke_dict_.Type__auto:
|
||||
if (tag_rdr.Read_and_move(Byte_ascii.Brack_bgn)) { // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25
|
||||
autonumber_id = tag_rdr.Read_int_to(Byte_ascii.Brack_end); // extract int; EX: "<a ...>[123]</a>"
|
||||
rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that auto is not recursive; EX: "[https://a.org]"
|
||||
if (tag_rdr.Read_and_move(Byte_ascii.Brack_bgn)) { // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25
|
||||
this.autonumber_id = tag_rdr.Read_int_to(Byte_ascii.Brack_end); // extract int; EX: "<a ...>[123]</a>"
|
||||
this.rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that auto is not recursive; EX: "[https://a.org]"
|
||||
}
|
||||
break;
|
||||
}
|
||||
hdoc_wkr.On_lnke(rng_bgn, rng_end, lnke_type, autonumber_id, href_bgn, href_end);
|
||||
hdoc_wkr.On_lnke(this);
|
||||
return rng_end;
|
||||
}
|
||||
public static final byte[] Bry__rel__nofollow = Bry_.new_a7("nofollow");
|
||||
}
|
||||
|
||||
@@ -19,14 +19,13 @@ package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; impo
|
||||
import gplx.core.brys.*;
|
||||
public class Xoh_lnki_dict_ {
|
||||
public static final byte // SERIALIZED
|
||||
Type__caption_n = Byte_ascii.Num_0
|
||||
, Type__caption_y = Byte_ascii.Num_1
|
||||
, Type__same = Xoh_ttl_matcher.Tid__same // EX: [[A]]
|
||||
, Type__diff = Xoh_ttl_matcher.Tid__diff // EX: [[A|b]]
|
||||
, Type__trail = Xoh_ttl_matcher.Tid__trail // EX: [[A|b]]
|
||||
Capt__same = Xoh_ttl_matcher.Tid__same // EX: [[A]]
|
||||
, Capt__diff = Xoh_ttl_matcher.Tid__diff // EX: [[A|b]]
|
||||
, Capt__trail = Xoh_ttl_matcher.Tid__tail // EX: [[A|b]]
|
||||
, Capt__head = Xoh_ttl_matcher.Tid__head // EX: [[A_(b)|A]]
|
||||
;
|
||||
public static void Ns_encode(Bry_bfr bfr, Xoa_ttl ttl) {
|
||||
gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Encode(1, bfr, ttl.Ns().Id() + 2);
|
||||
public static void Ns_encode(Bry_bfr bfr, int ns_id) {
|
||||
gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Encode(1, bfr, ns_id + 2);
|
||||
}
|
||||
public static int Ns_decode(Bry_rdr rdr) {
|
||||
return rdr.Read_int_by_base85(1) - 2;
|
||||
|
||||
@@ -16,92 +16,155 @@ 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.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.encoders.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.encoders.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xoh_lnki_hzip implements Xoh_hzip_wkr {
|
||||
private Xow_ttl_parser ttl_parser; private int uid;
|
||||
public void Ttl_parser_(Xow_ttl_parser ttl_parser) {this.ttl_parser = ttl_parser; this.uid = 1;} // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
|
||||
public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
private final int[] flag_ary;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ ( 1, 2, 3);
|
||||
public String Key() {return Xoh_hzip_dict_.Key__lnki;}
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_lnki_parser arg) {
|
||||
byte lnki_type = arg.Lnki_type();
|
||||
Xoa_ttl page_ttl = arg.Anch_href_parser().Page_ttl();
|
||||
public Xoh_lnki_hzip() {this.flag_ary = flag_bldr.Val_ary();}
|
||||
public Xoh_lnki_hzip Encode(Bry_bfr bfr, Xoh_hdoc_ctx hctx, Hzip_stat_itm stat_itm, byte[] src, Xoh_lnki_parser arg) {
|
||||
byte capt_type = arg.Capt_type();
|
||||
Xoh_anch_href_parser anch_href_parser = arg.Anch_href_parser();
|
||||
Xoa_ttl page_ttl = anch_href_parser.Page_ttl();
|
||||
int page_ns_id = page_ttl.Ns().Id();
|
||||
boolean page_ns_id_is_main = page_ns_id == Xow_ns_.Tid__main;
|
||||
int href_type = anch_href_parser.Tid();
|
||||
flag_ary[ 0] = page_ns_id_is_main ? 1 : 0;
|
||||
flag_ary[ 1] = href_type;
|
||||
flag_ary[ 2] = capt_type;
|
||||
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__lnki);
|
||||
bfr.Add_byte(lnki_type);
|
||||
Xoh_hzip_int_.Encode(1, bfr, page_ttl.Ns().Ord()); // NOTE: ord b/c Xoh_int does not support negative numbers
|
||||
// if (site_end - site_bgn > 0)
|
||||
// bfr.Add_byte(Xoh_hzip_dict_.Escape).Add_mid(src, site_bgn, site_end).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
switch (lnki_type) {
|
||||
case Xoh_lnki_dict_.Type__same:
|
||||
Xoh_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
|
||||
if (!page_ns_id_is_main)
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, page_ns_id);
|
||||
switch (href_type) {
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
bfr.Add_mid(src, anch_href_parser.Site_bgn(), anch_href_parser.Site_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
}
|
||||
switch (capt_type) {
|
||||
case Xoh_lnki_dict_.Capt__same:
|
||||
stat_itm.Lnki_text_n_add();
|
||||
byte[] ttl_bry = page_ttl.Ns().Id_is_main()
|
||||
byte[] ttl_bry = page_ns_id_is_main
|
||||
? arg.Capt_bry() // main ns should write html_text; handles [[a]] with html of '<a href="A">a</a>'
|
||||
: page_ttl.Page_db(); // non-main ns should write page_db only; EX: "Template:A" should write "A" since "Template" will be inferred by ns_id
|
||||
bfr.Add(ttl_bry).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Type__diff:
|
||||
case Xoh_lnki_dict_.Capt__diff:
|
||||
stat_itm.Lnki_text_y_add();
|
||||
bfr.Add(arg.Anch_href_parser().Page_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
bfr.Add(arg.Capt_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Type__trail:
|
||||
case Xoh_lnki_dict_.Capt__trail:
|
||||
bfr.Add(arg.Capt_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
bfr.Add(arg.Trail_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Capt__head:
|
||||
bfr.Add(arg.Capt_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
bfr.Add(arg.Trail_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
byte lnki_type = rdr.Read_byte();
|
||||
int ns_ord = rdr.Read_int_by_base85(1);
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
int flag = rdr.Read_int_by_base85(1);
|
||||
flag_bldr.Decode(flag);
|
||||
boolean page_ns_id_is_main = flag_bldr.Get_as_bool(0);
|
||||
byte href_type = flag_bldr.Get_as_byte(1);
|
||||
byte capt_type = flag_bldr.Get_as_byte(2);
|
||||
|
||||
int ns_id = Xow_ns_.Tid__main;
|
||||
if (!page_ns_id_is_main)
|
||||
ns_id = Xoh_lnki_dict_.Ns_decode(rdr);
|
||||
int site_bgn = -1, site_end = -1;
|
||||
if (rdr.Is(Xoh_hzip_dict_.Escape)) {
|
||||
site_bgn = rdr.Pos();
|
||||
site_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
switch (href_type) {
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
site_bgn = rdr.Pos();
|
||||
site_end = rdr.Find_fwd_lr();
|
||||
break;
|
||||
}
|
||||
boolean site_exists = site_end - site_bgn > 0;
|
||||
int page_bgn = rdr.Pos();
|
||||
int page_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
int page_end = rdr.Find_fwd_lr();
|
||||
int capt_bgn = -1, capt_end = -1;
|
||||
if (lnki_type != Xoh_lnki_dict_.Type__same) {
|
||||
if (capt_type != Xoh_lnki_dict_.Capt__same) {
|
||||
capt_bgn = rdr.Pos();
|
||||
capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
capt_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
|
||||
byte[] page_bry = Bry_.Mid(src, page_bgn, page_end);
|
||||
Xow_ns ns = ttl_parser.Ns_mgr().Ords_get_at(ns_ord);
|
||||
Xoa_ttl ttl = ttl_parser.Ttl_parse(ns.Id(), page_bry); if (ttl == null) rdr.Fail("invalid ttl", String_.Empty, String_.new_u8(page_bry)); // TODO: parse title based on site
|
||||
byte[] ttl__full_db = ttl.Full_db();
|
||||
byte[] page_bry = null;
|
||||
if (capt_type == Xoh_lnki_dict_.Capt__head)
|
||||
page_bry = Bry_.Add(Bry_.Mid(src, page_bgn, page_end), Bry_.Mid(src, capt_bgn, capt_end));
|
||||
else
|
||||
page_bry = Bry_.Mid(src, page_bgn, page_end);
|
||||
byte[] title_bry = null, href_bry = null;
|
||||
if (href_type == Xoh_anch_href_parser.Tid__anch)
|
||||
href_bry = page_bry;
|
||||
else {
|
||||
Xow_ns ns = hctx.Wiki__ttl_parser().Ns_mgr().Ids_get_or_null(ns_id);
|
||||
Xoa_ttl ttl = hctx.Wiki__ttl_parser().Ttl_parse(ns.Id(), page_bry); if (ttl == null) rdr.Fail("invalid ttl", String_.Empty, String_.new_u8(page_bry)); // TODO: parse title based on site
|
||||
href_bry = ttl.Full_db();
|
||||
title_bry = ttl.Full_txt();
|
||||
if (href_type == Xoh_anch_href_parser.Tid__site) {
|
||||
href_bry = ttl.Page_db(); // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A"
|
||||
}
|
||||
}
|
||||
|
||||
// gen html
|
||||
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
|
||||
if (site_exists) bfr.Add(Xoh_href_.Bry__wiki).Add_mid(src, site_bgn, site_end);
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/"
|
||||
bfr.Add(ttl.Full_db());
|
||||
bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(++uid);
|
||||
bfr.Add_str_a7("\" title=\"");
|
||||
byte[] title_bry = site_exists ? ttl.Page_db() : ttl__full_db; // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A"
|
||||
bfr.Add(Html_utl.Escape_html_as_bry(title_bry)).Add_str_a7("\">");
|
||||
switch (lnki_type) {
|
||||
case Xoh_lnki_dict_.Type__same:
|
||||
if (ttl.Ns().Id_is_main())
|
||||
switch (href_type) {
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
bfr.Add(Xoh_href_.Bry__wiki).Add_mid(src, site_bgn, site_end);
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/"
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__anch:
|
||||
bfr.Add_byte(Byte_ascii.Hash); // "#"
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__wiki:
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/"
|
||||
break;
|
||||
}
|
||||
bfr.Add(href_bry);
|
||||
bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(hctx.Lnki__uid__nxt());
|
||||
if (href_type != Xoh_anch_href_parser.Tid__anch) {
|
||||
bfr.Add_str_a7("\" title=\"");
|
||||
bfr.Add(Html_utl.Escape_html_as_bry(title_bry));
|
||||
}
|
||||
bfr.Add_str_a7("\">");
|
||||
if ( href_type == Xoh_anch_href_parser.Tid__anch
|
||||
&& capt_type != Xoh_lnki_dict_.Capt__diff )
|
||||
bfr.Add_byte(Byte_ascii.Hash);
|
||||
switch (capt_type) {
|
||||
case Xoh_lnki_dict_.Capt__same:
|
||||
if (ns_id == Xow_ns_.Tid__main)
|
||||
bfr.Add_mid(src, page_bgn, page_end);
|
||||
else
|
||||
bfr.Add(ttl.Full_txt());
|
||||
bfr.Add(title_bry);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Type__diff:
|
||||
case Xoh_lnki_dict_.Capt__diff:
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Type__trail:
|
||||
case Xoh_lnki_dict_.Capt__trail:
|
||||
bfr.Add_mid(src, page_bgn, page_end);
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Capt__head:
|
||||
bfr.Add_mid(src, page_bgn, page_end);
|
||||
break;
|
||||
}
|
||||
bfr.Add_str_a7("</a>");
|
||||
return rdr.Pos();
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_lnki_hzip rv = new Xoh_lnki_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
||||
|
||||
@@ -16,30 +16,39 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_lnki_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Page__basic() {
|
||||
fxt.Test__bicode("~$1#A~", Xoh_lnki_html__hdump__tst.Html__same);
|
||||
fxt.Test__bicode("~$IA~", Xoh_lnki_html__hdump__tst.Html__same);
|
||||
}
|
||||
@Test public void Page__alt_case() {
|
||||
fxt.Test__bicode("~$1#a~", "<a href='/wiki/A' id='xowa_lnki_2' title='A'>a</a>");
|
||||
fxt.Test__bicode("~$Ia~", "<a href='/wiki/A' id='xowa_lnki_2' title='A'>a</a>");
|
||||
}
|
||||
@Test public void Page__ns() {
|
||||
fxt.Test__bicode("~$1-A~", "<a href='/wiki/Template:A' id='xowa_lnki_2' title='Template:A'>Template:A</a>");
|
||||
fxt.Test__bicode("~$)-A~", "<a href='/wiki/Template:A' id='xowa_lnki_2' title='Template:A'>Template:A</a>");
|
||||
}
|
||||
@Test public void Anch__basic() {
|
||||
fxt.Test__bicode("$Ya", "<a href='#a' id='xowa_lnki_2'>#a</a>");
|
||||
}
|
||||
@Test public void Capt__basic() {
|
||||
fxt.Test__bicode("~$2#A~b~", Xoh_lnki_html__hdump__tst.Html__diff);
|
||||
fxt.Test__bicode("~$JA~b~", Xoh_lnki_html__hdump__tst.Html__diff);
|
||||
}
|
||||
@Test public void Capt__nest() {
|
||||
fxt.Test__bicode
|
||||
( "~$2#A~<a href=\"/wiki/C\" id=\"xowa_lnki_3\" title=\"C\">C1</a>D~"
|
||||
( "~$JA~<a href=\"/wiki/C\" id=\"xowa_lnki_3\" title=\"C\">C1</a>D~"
|
||||
, "<a href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><a href=\"/wiki/C\" id=\"xowa_lnki_3\" title=\"C\">C1</a>D</a>"
|
||||
);
|
||||
// old: probably broken; fxt.Test__bicode("~$1!#A~~$1!#C~C1</a>D</a>", "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><a data-xotype='lnki1' href=\"/wiki/C\" id=\"xowa_lnki_2\" title=\"C\">C1</a>D</a>");
|
||||
}
|
||||
@Test public void Trail__basic() {
|
||||
fxt.Test__bicode("~$3#A~b~", Xoh_lnki_html__hdump__tst.Html__trail);
|
||||
@Test public void Tail__basic() {
|
||||
fxt.Test__bicode("~$KA~b~", Xoh_lnki_html__hdump__tst.Html__trail);
|
||||
}
|
||||
@Test public void Head__basic() {
|
||||
fxt.Test__bicode("~$LA~b~", "<a href='/wiki/Ab' id='xowa_lnki_2' title='Ab'>A</a>");
|
||||
}
|
||||
@Test public void Head__case() {
|
||||
fxt.Test__bicode("~$La~b~", "<a href='/wiki/Ab' id='xowa_lnki_2' title='Ab'>a</a>");
|
||||
}
|
||||
// @Test public void Capt__site__xwiki() {
|
||||
// fxt.Parser_fxt().Init_xwiki_add_wiki_and_user_("wikt", "en.wiktionary.org");
|
||||
|
||||
@@ -24,30 +24,37 @@ public class Xoh_lnki_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
|
||||
public byte Capt_type() {return capt_type;} private byte capt_type;
|
||||
public byte[] Capt_bry() {return capt_bry;} private byte[] capt_bry;
|
||||
public byte[] Trail_bry() {return trail_bry;} private byte[] trail_bry;
|
||||
public Xoh_anch_href_parser Anch_href_parser() {return anch_href_parser;} private final Xoh_anch_href_parser anch_href_parser = new Xoh_anch_href_parser();
|
||||
public int Parse(Xoh_hdoc_wkr wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag anch_tag, Xow_ttl_parser ttl_parser) {// <a href="/wiki/A" title="A">b</a>
|
||||
public int Parse(Xoh_hdoc_wkr wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_tag, Xow_ttl_parser ttl_parser) {// <a href="/wiki/A" title="A">b</a>
|
||||
this.rng_bgn = anch_tag.Src_bgn(); this.rng_end = anch_tag.Src_end();
|
||||
rdr.Ctor_by_page(Bry_.Empty, src, src.length);
|
||||
anch_href_parser.Parse(rdr, wkr.Ctx().Wiki(), anch_tag); // href='/wiki/A'
|
||||
rdr.Init_by_page(Bry_.Empty, src, src.length);
|
||||
anch_href_parser.Parse(rdr, hctx.Wiki__ttl_parser(), anch_tag); // href='/wiki/A'
|
||||
Html_tag lnki_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
|
||||
int capt_bgn = rng_end; int capt_end = lnki_tail.Src_bgn(); // get capt between "<a>" and "</a>
|
||||
if ( anch_href_parser.Tid() == Xoh_anch_href_parser.Tid__anch
|
||||
&& src[capt_bgn] == Byte_ascii.Hash)
|
||||
++capt_bgn;
|
||||
this.rng_end = lnki_tail.Src_end();
|
||||
this.lnki_type = ttl_matcher.Match(rdr, ttl_parser, src, anch_href_parser.Page_bgn(), anch_href_parser.Page_end(), src, capt_bgn, capt_end);
|
||||
this.capt_type = ttl_matcher.Match(rdr, ttl_parser, src, anch_href_parser.Page_bgn(), anch_href_parser.Page_end(), src, capt_bgn, capt_end);
|
||||
this.capt_bry = trail_bry = null;
|
||||
switch (lnki_type) {
|
||||
switch (capt_type) {
|
||||
case Xoh_ttl_matcher.Tid__same:
|
||||
this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
|
||||
break;
|
||||
case Xoh_ttl_matcher.Tid__diff:
|
||||
this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
|
||||
break;
|
||||
case Xoh_ttl_matcher.Tid__trail:
|
||||
case Xoh_ttl_matcher.Tid__tail:
|
||||
this.capt_bry = Bry_.Mid(src, capt_bgn, ttl_matcher.Trail_bgn());
|
||||
this.trail_bry = Bry_.Mid(src, ttl_matcher.Trail_bgn(), capt_end);
|
||||
break;
|
||||
case Xoh_ttl_matcher.Tid__head:
|
||||
this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
|
||||
this.trail_bry = Bry_.Mid(src, ttl_matcher.Trail_bgn(), anch_href_parser.Page_end());
|
||||
break;
|
||||
}
|
||||
wkr.On_lnki(this);
|
||||
return rng_end;
|
||||
|
||||
@@ -20,9 +20,9 @@ import gplx.core.brys.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_ttl_matcher {
|
||||
public int Trail_bgn() {return trail_bgn;} private int trail_bgn;
|
||||
public int Trail_bgn() {return midpoint_pos;} private int midpoint_pos;
|
||||
public byte Match(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, byte[] page_bry, int page_bgn, int page_end, byte[] capt_bry, int capt_bgn, int capt_end) {
|
||||
trail_bgn = -1;
|
||||
midpoint_pos = -1;
|
||||
int page_len = page_end - page_bgn; if (page_len == 0) page_bry = Xoa_page_.Main_page_bry; // NOTE: href="/site/en.wikipedia.org/wiki/" can be null
|
||||
Xoa_ttl page = ttl_parser.Ttl_parse(page_bry, page_bgn, page_end); if (page == null) owner_rdr.Fail("invalid page", "page", page_bry);
|
||||
Xow_ns ns = page.Ns();
|
||||
@@ -30,8 +30,11 @@ public class Xoh_ttl_matcher {
|
||||
byte[] ns_name_txt = ns.Name_ui_w_colon(); // EX: 11="Template talk:"
|
||||
int ns_name_txt_len = ns_name_txt.length;
|
||||
int ns_name_txt_end = capt_bgn + ns_name_txt_len;
|
||||
if (Bry_.Match(capt_bry, capt_bgn, ns_name_txt_end, ns_name_txt, 0, ns_name_txt_len))
|
||||
capt_bgn = page_bgn = ns_name_txt_end;
|
||||
if (Bry_.Match(capt_bry, capt_bgn, ns_name_txt_end, ns_name_txt, 0, ns_name_txt_len)) {
|
||||
capt_bgn = ns_name_txt_end;
|
||||
page_bgn += ns_name_txt_len;
|
||||
page_len = page_end - page_bgn;
|
||||
}
|
||||
else
|
||||
return Tid__diff;
|
||||
}
|
||||
@@ -39,8 +42,8 @@ public class Xoh_ttl_matcher {
|
||||
for (int i = 0; i < capt_len; ++i) {
|
||||
byte capt_byte = capt_bry[i + capt_bgn];
|
||||
if (i == page_len) {
|
||||
trail_bgn = i + capt_bgn;
|
||||
return Tid__trail;
|
||||
midpoint_pos = i + capt_bgn;
|
||||
return Tid__tail;
|
||||
}
|
||||
byte page_byte = page_bry[i + page_bgn];
|
||||
if (page_byte == capt_byte) continue;
|
||||
@@ -56,11 +59,17 @@ public class Xoh_ttl_matcher {
|
||||
continue;
|
||||
return Tid__diff;
|
||||
}
|
||||
return Tid__same;
|
||||
if (capt_len == page_len)
|
||||
return Tid__same;
|
||||
else {
|
||||
midpoint_pos = capt_len + page_bgn;
|
||||
return Tid__head;
|
||||
}
|
||||
}
|
||||
public static final byte
|
||||
Tid__same = Byte_ascii.Num_1 // "A", "A"; "1|A"
|
||||
, Tid__diff = Byte_ascii.Num_2 // "A", "B"; "2|A|B"
|
||||
, Tid__trail = Byte_ascii.Num_3 // "A", "As"; "3|A|s"
|
||||
Tid__same = 0 // "A" , "A" , "A"
|
||||
, Tid__diff = 1 // "A" , "B" , "A|B"
|
||||
, Tid__tail = 2 // "A" , "As" , "A|s"
|
||||
, Tid__head = 3 // "A_(b)" , "A" , "A|_(b)"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ public class Xoh_ttl_matcher_tst {
|
||||
}
|
||||
@Test public void Ns__same() {fxt.Test__match("Help_talk:Ab" , "Help talk:Ab", Xoh_ttl_matcher.Tid__same);}
|
||||
@Test public void Ns__diff() {fxt.Test__match("Help_talk:Ab" , "Help_talk:Ab", Xoh_ttl_matcher.Tid__diff);}
|
||||
@Test public void Trail__same() {fxt.Test__match("A" , "Abc", Xoh_ttl_matcher.Tid__trail, 1);}
|
||||
@Test public void Tail__same() {fxt.Test__match("A" , "Abc" , Xoh_ttl_matcher.Tid__tail, 1);}
|
||||
@Test public void Head__same() {fxt.Test__match("Ab" , "A" , Xoh_ttl_matcher.Tid__head, 1);}
|
||||
}
|
||||
class Xoh_ttl_matcher_fxt {
|
||||
private final Xoh_ttl_matcher matcher = new Xoh_ttl_matcher();
|
||||
@@ -44,7 +45,7 @@ class Xoh_ttl_matcher_fxt {
|
||||
public void Test__match(String page_str, String capt_str, int expd_tid, int expd_trail_bgn) {
|
||||
byte[] page_bry = Bry_.new_u8(page_str);
|
||||
byte[] capt_bry = Bry_.new_u8(capt_str);
|
||||
Tfds.Eq_int(expd_tid , matcher.Match(rdr.Ctor_by_page(Bry_.Empty, page_bry, page_bry.length), wiki, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length));
|
||||
Tfds.Eq_int(expd_tid , matcher.Match(rdr.Init_by_page(Bry_.Empty, page_bry, page_bry.length), wiki, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length));
|
||||
Tfds.Eq_int(expd_trail_bgn , matcher.Trail_bgn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,12 @@ import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_anch_href_parser implements Xoh_itm_parser {
|
||||
private byte[] src; private Xoa_ttl page_ttl; Xow_ttl_parser ttl_parser;
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
private Xoa_ttl page_ttl; Xow_ttl_parser ttl_parser;
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash);
|
||||
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
|
||||
public Html_atr Atr() {return atr;} private Html_atr atr;
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Val_bgn() {return val_bgn;} private int val_bgn;
|
||||
public int Val_end() {return val_end;} private int val_end;
|
||||
public int Site_bgn() {return site_bgn;} private int site_bgn;
|
||||
@@ -39,27 +42,58 @@ public class Xoh_anch_href_parser implements Xoh_itm_parser {
|
||||
return page_ttl;
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, Html_tag tag) {
|
||||
Html_atr atr = tag.Atrs__get_by(Html_atr_.Bry__href);
|
||||
this.atr = tag.Atrs__get_by_or_fail(Html_atr_.Bry__href);
|
||||
Parse(owner_rdr, ttl_parser, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, int href_bgn, int href_end) {
|
||||
rdr.Init_by_sub(owner_rdr, "lnki.href", href_bgn, href_end).Dflt_dlm_(Byte_ascii.Slash);
|
||||
site_bgn = -1; site_end = -1; page_bry = null; page_ttl = null;
|
||||
rdr.Init_by_sub(owner_rdr, "lnki.href", href_bgn, href_end);
|
||||
site_bgn = site_end = page_bgn = page_end = -1;
|
||||
tid = Tid__null;
|
||||
page_bry = null; page_ttl = null;
|
||||
this.val_bgn = href_bgn; this.val_end = href_end;
|
||||
this.src = owner_rdr.Src(); this.ttl_parser = ttl_parser;
|
||||
rdr.Chk(Byte_ascii.Slash);
|
||||
if (rdr.Chk(trie) == Href_tid__site) { // EX: // "/site/wiki/A"
|
||||
site_bgn = rdr.Pos();
|
||||
site_end = rdr.Find_fwd_lr();
|
||||
rdr.Chk(Bry__wiki);
|
||||
if (val_end == val_bgn) {
|
||||
page_bgn = page_end = 0;
|
||||
return; // handle empty String separately; EX: href=""
|
||||
}
|
||||
int pos = href_bgn;
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Hash:
|
||||
tid = Tid__anch;
|
||||
page_bgn = pos + 1; // position page_bgn after #
|
||||
page_end = val_end; // anch ends at EOS
|
||||
break;
|
||||
default:
|
||||
tid = Tid__inet;
|
||||
page_bgn = pos; // position page_bgn after #
|
||||
page_end = val_end; // anch ends at EOS
|
||||
break;
|
||||
case Byte_ascii.Slash:
|
||||
rdr.Move_by_one(); // skip "/"
|
||||
if (rdr.Chk(trie) == Tid__site) { // EX: "/site/wiki/A"
|
||||
tid = Tid__site;
|
||||
site_bgn = rdr.Pos();
|
||||
site_end = rdr.Find_fwd_lr();
|
||||
rdr.Chk(Bry__wiki);
|
||||
}
|
||||
else {
|
||||
tid = Tid__wiki;
|
||||
}
|
||||
page_bgn = rdr.Pos();
|
||||
page_end = rdr.Src_end();
|
||||
break;
|
||||
}
|
||||
page_bgn = rdr.Pos();
|
||||
page_end = rdr.Src_end();
|
||||
}
|
||||
private static final byte Href_tid__wiki = 1, Href_tid__site = 2;
|
||||
public static final byte
|
||||
Tid__null = 0 // EX: href=""
|
||||
, Tid__wiki = 1 // EX: href="/wiki/A"
|
||||
, Tid__site = 2 // EX: href="/site/en.wikipedia.org/wiki/A"
|
||||
, Tid__anch = 3 // EX: href="#A"
|
||||
, Tid__inet = 4 // EX: href="https://a.org/A"
|
||||
;
|
||||
private static final byte[] Bry__site = Bry_.new_a7("site/"), Bry__wiki = Bry_.new_a7("wiki/");
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_bry_byte(Bry__wiki, Href_tid__wiki)
|
||||
.Add_bry_byte(Bry__site, Href_tid__site)
|
||||
.Add_bry_byte(Bry__wiki, Tid__wiki)
|
||||
.Add_bry_byte(Bry__site, Tid__site)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,15 @@ public class Xoh_anch_href_parser_tst {
|
||||
@Test public void Page() {
|
||||
fxt.Test__parse("/wiki/B", "", "B");
|
||||
}
|
||||
@Test public void Href() {
|
||||
fxt.Test__parse("#A", "", "A");
|
||||
}
|
||||
@Test public void None() {
|
||||
fxt.Test__parse("", "", "");
|
||||
}
|
||||
@Test public void Inet() {
|
||||
fxt.Test__parse("http://a.org", "", "http://a.org");
|
||||
}
|
||||
@Test public void Fail__1st_seg_must_be_site_or_wiki() {
|
||||
fxt.Test__parse__fail("/fail/A", "failed trie check: mid='fail/A' ctx='Main_Page' wkr='lnki.href' excerpt='/fail/A'");
|
||||
}
|
||||
|
||||
@@ -16,6 +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.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
public interface Xoh_arg_img_core extends Bry_fmtr_arg {
|
||||
public interface Xoh_arg_img_core extends gplx.core.brys.Bfr_arg {
|
||||
Xoh_arg_img_core Init(int uid, byte[] src, int w, int h);
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
public class Xoh_arg_img_core__basic implements Xoh_arg_img_core {
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
public class Xoh_arg_img_core__basic extends gplx.core.brys.Bfr_arg_base implements Xoh_arg_img_core {
|
||||
private byte[] src; private int w, h;
|
||||
public Xoh_arg_img_core Init(int uid, byte[] src, int w, int h) {this.src = src; this.w = w; this.h = h; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr_img_atrs.Bld_bfr_many(bfr, src, w, h);
|
||||
}
|
||||
private Bry_fmtr fmtr_img_atrs = Bry_fmtr.new_(" src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"", "img_src", "img_w", "img_h");
|
||||
|
||||
@@ -16,13 +16,13 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
public class Xoh_arg_img_core__hdump implements Xoh_arg_img_core {
|
||||
public class Xoh_arg_img_core__hdump extends gplx.core.brys.Bfr_arg_base implements Xoh_arg_img_core {
|
||||
private int uid;
|
||||
public Xoh_arg_img_core Init(int uid, byte[] img_src, int img_w, int img_h) {
|
||||
this.uid = uid;
|
||||
return this;
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add(gplx.xowa.htmls.core.makes.Xoh_make_trie_.Bry__img);
|
||||
bfr.Add_int_variable(uid);
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
@@ -26,7 +27,7 @@ public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
|
||||
arg_img_core = New_arg_img_core();
|
||||
}
|
||||
@gplx.Internal @gplx.Virtual protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__basic();}
|
||||
@gplx.Virtual public void Html_full_media(Bry_bfr tmp_bfr, byte[] a_href, byte[] a_title, Bry_fmtr_arg html) {fmtr_full_media.Bld_bfr_many(tmp_bfr, a_href, a_title, html);}
|
||||
@gplx.Virtual public void Html_full_media(Bry_bfr tmp_bfr, byte[] a_href, byte[] a_title, Bfr_arg html) {fmtr_full_media.Bld_bfr_many(tmp_bfr, a_href, a_title, html);}
|
||||
private final Bry_fmtr fmtr_full_media = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"~{a_href}\" xowa_title=\"~{a_xowa_title}\">~{html}"
|
||||
, "</a>"
|
||||
@@ -77,7 +78,7 @@ public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
|
||||
, " </div>"
|
||||
), "uid", "a_href", "a_title", "img_core", "img_alt");
|
||||
|
||||
public void Html_thumb_part_caption(Bry_bfr tmp_bfr, byte[] magnify_btn, Bry_fmtr_arg caption) {fmtr_thumb_part_caption.Bld_bfr_many(tmp_bfr, magnify_btn, caption);}
|
||||
public void Html_thumb_part_caption(Bry_bfr tmp_bfr, byte[] magnify_btn, Bfr_arg caption) {fmtr_thumb_part_caption.Bld_bfr_many(tmp_bfr, magnify_btn, caption);}
|
||||
private Bry_fmtr fmtr_thumb_part_caption = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"thumbcaption\">~{magnify_btn}"
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.htmls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
|
||||
@@ -39,7 +40,7 @@ public class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base {
|
||||
+ "</a>"
|
||||
, "a_href", "a_class", "a_rel", "a_title", "img_alt", "img_xoimg", "img_core", "img_class"
|
||||
);
|
||||
// public override void Html_full_media(Bry_bfr tmp_bfr, byte[] a_href, byte[] a_title, Bry_fmtr_arg html) {
|
||||
// public override void Html_full_media(Bry_bfr tmp_bfr, byte[] a_href, byte[] a_title, Bfr_arg html) {
|
||||
// fmtr_full_media.Bld_bfr_many(tmp_bfr, a_href, a_title, html);
|
||||
// }
|
||||
@Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
@@ -47,9 +48,9 @@ public class Xoh_file_wtr__basic {
|
||||
if (div_width < 1)
|
||||
div_width = wiki.Html_mgr().Img_thumb_width();
|
||||
int lnki_halign = lnki.Align_h();
|
||||
if (lnki_halign == Xop_lnki_align_h.Null)
|
||||
if (lnki_halign == Xop_lnki_align_h_.Null)
|
||||
lnki_halign = wiki.Lang().Img_thumb_halign_default(); // if halign is not supplied, then default to align for language
|
||||
byte[] lnki_halign_bry = Xop_lnki_align_h.Html_names[lnki_halign];
|
||||
byte[] lnki_halign_bry = Xop_lnki_align_h_.Html_names[lnki_halign];
|
||||
byte[] lnki_href = wiki.Appe().Html__href_wtr().Build_to_bry(wiki, lnki.Ttl());
|
||||
byte[] img_view_src = xfer_itm.Html_view_url().To_http_file_bry();
|
||||
byte[] img_orig_src = xfer_itm.Html_orig_url().To_http_file_bry();
|
||||
@@ -109,7 +110,7 @@ public class Xoh_file_wtr__basic {
|
||||
}
|
||||
private void Write_file_image(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_file_itm xfer_itm, int uid, boolean lnki_is_thumbable, int div_width, int lnki_halign, byte[] lnki_halign_bry
|
||||
, byte[] lnki_ttl, Xof_ext orig_ext, byte[] lnki_href, byte[] img_view_src, byte[] img_orig_src, byte[] alt) {
|
||||
if (lnki_halign == Xop_lnki_align_h.Center) bfr.Add(Div_center_bgn);
|
||||
if (lnki_halign == Xop_lnki_align_h_.Center) bfr.Add(Div_center_bgn);
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
byte[] anchor_title = html_wtr.Cfg().Lnki__title()
|
||||
? Arg_anchor_title(tmp_bfr, src, lnki, lnki_ttl, anchor_title_wkr) // NOTE: Arg_anchor_title should only be called if there is no caption, else refs may not show; DATE:2014-03-05
|
||||
@@ -125,14 +126,14 @@ public class Xoh_file_wtr__basic {
|
||||
&& Bry_.Len_eq_0(alt) // NOTE: if no alt, always use caption; DATE:2013-07-22
|
||||
&& !lnki.Alt_exists() // unless blank alt exists; EX: [[File:A.png|a|alt=]] should have alt of "", not "a"
|
||||
) {
|
||||
Arg_caption(ctx, src, Xoh_wtr_ctx.Alt, lnki).Fmt__do(tmp_bfr);
|
||||
Arg_caption(ctx, src, Xoh_wtr_ctx.Alt, lnki).Bfr_arg__add(tmp_bfr);
|
||||
alt = tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
boolean div_align_exists = false;
|
||||
switch (lnki.Align_h()) {
|
||||
case Xop_lnki_align_h.Left: bfr.Add(Div_float_left) .Add_byte_nl(); div_align_exists = true; break;
|
||||
case Xop_lnki_align_h.Right: bfr.Add(Div_float_right).Add_byte_nl(); div_align_exists = true; break;
|
||||
case Xop_lnki_align_h.None: bfr.Add(Div_float_none) .Add_byte_nl(); div_align_exists = true; break;
|
||||
case Xop_lnki_align_h_.Left: bfr.Add(Div_float_left) .Add_byte_nl(); div_align_exists = true; break;
|
||||
case Xop_lnki_align_h_.Right: bfr.Add(Div_float_right).Add_byte_nl(); div_align_exists = true; break;
|
||||
case Xop_lnki_align_h_.None: bfr.Add(Div_float_none) .Add_byte_nl(); div_align_exists = true; break;
|
||||
}
|
||||
Arg_nde_tkn lnki_link_tkn = lnki.Link_tkn();
|
||||
byte img_cls_tid = lnki.Border() == Bool_.Y_byte ? Xoh_img_cls_.Tid__thumbborder : Xoh_img_cls_.Tid__none;
|
||||
@@ -150,7 +151,7 @@ public class Xoh_file_wtr__basic {
|
||||
}
|
||||
if (div_align_exists) bfr.Add(Html_tag_.Div_rhs); // close div from above
|
||||
}
|
||||
if (lnki_halign == Xop_lnki_align_h.Center) bfr.Add(Html_tag_.Div_rhs);
|
||||
if (lnki_halign == Xop_lnki_align_h_.Center) bfr.Add(Html_tag_.Div_rhs);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
private byte[] Arg_content_thumb(Xoh_file_img_wkr lnki_file_wkr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_file_itm xfer_itm, int uid, byte[] lnki_href, byte[] view_src, byte[] img_orig_src, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_title) {
|
||||
@@ -184,7 +185,7 @@ public class Xoh_file_wtr__basic {
|
||||
return scratch_bfr.To_bry_and_clear();
|
||||
}
|
||||
private byte[] Arg_caption_div(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int uid, byte[] img_orig_src, byte[] lnki_href) {
|
||||
Bry_fmtr_arg caption = Arg_caption(ctx, src, Xoh_wtr_ctx.Basic, lnki);
|
||||
Bfr_arg caption = Arg_caption(ctx, src, Xoh_wtr_ctx.Basic, lnki);
|
||||
byte[] magnify_btn = Bry_.Empty;
|
||||
if (lnki.Media_icon()) {
|
||||
if (msg_file_enlarge == null) msg_file_enlarge = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_file_enlarge);
|
||||
@@ -194,21 +195,21 @@ public class Xoh_file_wtr__basic {
|
||||
html_fmtr.Html_thumb_part_caption(scratch_bfr, magnify_btn, caption);
|
||||
return scratch_bfr.To_bry_and_clear();
|
||||
} private byte[] msg_file_enlarge;
|
||||
private Bry_fmtr_arg Arg_caption(Xop_ctx ctx, byte[] src, Xoh_wtr_ctx hctx_for_caption, Xop_lnki_tkn lnki) {
|
||||
return lnki.Caption_exists() ? caption_fmtr.Set(ctx, hctx_for_caption, src, lnki.Caption_val_tkn(), Xoh_lnki_text_fmtr.Null_fmtr) : Bry_fmtr_arg_.Noop;
|
||||
private Bfr_arg Arg_caption(Xop_ctx ctx, byte[] src, Xoh_wtr_ctx hctx_for_caption, Xop_lnki_tkn lnki) {
|
||||
return lnki.Caption_exists() ? caption_fmtr.Set(ctx, hctx_for_caption, src, lnki.Caption_val_tkn(), Xoh_lnki_text_fmtr.Null_fmtr) : Bfr_arg_.Noop;
|
||||
}
|
||||
public byte[] Arg_alt_text(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki) {
|
||||
if (!lnki.Alt_exists()) return Bry_.Empty;
|
||||
media_alt_fmtr.Set(ctx, Xoh_wtr_ctx.Alt, src, lnki.Alt_tkn().Val_tkn(), Xoh_lnki_text_fmtr.Null_fmtr);
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
media_alt_fmtr.Fmt__do(tmp_bfr);
|
||||
media_alt_fmtr.Bfr_arg__add(tmp_bfr);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private byte[] Arg_alt_html(Xop_ctx ctx, byte[] alt_src, Xop_lnki_tkn lnki) {
|
||||
if (!lnki.Alt_exists()) return Bry_.Empty;
|
||||
media_alt_fmtr.Set(ctx, Xoh_wtr_ctx.Basic, alt_src, lnki.Alt_tkn().Val_tkn(), html_fmtr.Html_thumb_part_alt_fmtr());
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
media_alt_fmtr.Fmt__do(tmp_bfr);
|
||||
media_alt_fmtr.Bfr_arg__add(tmp_bfr);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private byte[] Arg_play_btn(int uid, int width, int max_width, byte[] a_href, byte[] a_xowa_title) {
|
||||
@@ -225,7 +226,7 @@ public class Xoh_file_wtr__basic {
|
||||
Xop_tkn_itm anchor_title_tkn = lnki.Caption_tkn();
|
||||
if (anchor_title_tkn == Xop_tkn_null.Null_tkn) return Bry_.Empty; // no caption; return empty; (do not use lnki); DATE:2013-12-31
|
||||
tmp_bfr.Add(Atr_title);
|
||||
anchor_title_wkr.Set(src, anchor_title_tkn).Fmt__do(tmp_bfr);
|
||||
anchor_title_wkr.Set(src, anchor_title_tkn).Bfr_arg__add(tmp_bfr);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Quote);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
|
||||
@@ -16,9 +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.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoh_lnki_text_fmtr implements Bry_fmtr_arg { // formats alt or caption
|
||||
public class Xoh_lnki_text_fmtr extends gplx.core.brys.Bfr_arg_base { // formats alt or caption
|
||||
private final Bry_bfr_mkr bfr_mkr; private final Xoh_html_wtr html_wtr;
|
||||
private Xop_ctx ctx; private Xoh_wtr_ctx hctx; private byte[] src; private Xop_tkn_itm text_tkn; private Bry_fmtr fmtr;
|
||||
public Xoh_lnki_text_fmtr(Bry_bfr_mkr bfr_mkr, Xoh_html_wtr html_wtr) {this.bfr_mkr = bfr_mkr; this.html_wtr = html_wtr;}
|
||||
@@ -26,7 +27,7 @@ public class Xoh_lnki_text_fmtr implements Bry_fmtr_arg { // formats alt or capt
|
||||
this.ctx = ctx; this.hctx = hctx; this.src = src; this.text_tkn = text_tkn; this.fmtr = fmtr;
|
||||
return this;
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
html_wtr.Write_tkn(tmp_bfr, ctx, hctx, src, null, Xoh_html_wtr.Sub_idx_null, text_tkn);
|
||||
tmp_bfr.Mkr_rls();
|
||||
|
||||
@@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xoh_lnki_title_fmtr implements Bry_fmtr_arg {
|
||||
public class Xoh_lnki_title_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
public Xoh_lnki_title_fmtr Set(byte[] src, Xop_tkn_itm tkn) {this.src = src; this.tkn = tkn; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Bld_recurse(bfr, tkn);
|
||||
}
|
||||
public void Bld_recurse(Bry_bfr bfr, Xop_tkn_itm tkn) {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.mkrs; 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.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.htmls.core.wkrs.escapes.*; import gplx.xowa.htmls.core.wkrs.spaces.*;
|
||||
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*;
|
||||
public class Xoh_hdoc_mkr {
|
||||
private Gfo_poolable_mgr
|
||||
pool__escape__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_escape_hzip())
|
||||
, pool__space__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_space_hzip())
|
||||
, pool__hdr__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_hdr_hzip())
|
||||
, pool__lnke__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_lnke_hzip())
|
||||
, pool__lnki__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_lnki_hzip())
|
||||
, pool__img__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_img_hzip())
|
||||
, pool__thm__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_thm_hzip())
|
||||
;
|
||||
public Xoh_hzip_wkr Hzip__wkr(byte tid) {
|
||||
switch (tid) {
|
||||
case Xoh_hzip_dict_.Tid__escape: return Escape__hzip();
|
||||
case Xoh_hzip_dict_.Tid__space: return Space__hzip();
|
||||
case Xoh_hzip_dict_.Tid__hdr: return Hdr__hzip();
|
||||
case Xoh_hzip_dict_.Tid__lnke: return Lnke__hzip();
|
||||
case Xoh_hzip_dict_.Tid__lnki: return Lnki__hzip();
|
||||
case Xoh_hzip_dict_.Tid__img: return Img__hzip();
|
||||
case Xoh_hzip_dict_.Tid__thm: return Thm__hzip();
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public Xoh_escape_hzip Escape__hzip() {return (Xoh_escape_hzip) pool__escape__hzip.Get_fast();}
|
||||
public Xoh_space_hzip Space__hzip() {return (Xoh_space_hzip) pool__space__hzip.Get_fast();}
|
||||
public Xoh_hdr_hzip Hdr__hzip() {return (Xoh_hdr_hzip) pool__hdr__hzip.Get_fast();}
|
||||
public Xoh_lnke_hzip Lnke__hzip() {return (Xoh_lnke_hzip) pool__lnke__hzip.Get_fast();}
|
||||
public Xoh_lnki_hzip Lnki__hzip() {return (Xoh_lnki_hzip) pool__lnki__hzip.Get_fast();}
|
||||
public Xoh_img_hzip Img__hzip() {return (Xoh_img_hzip) pool__img__hzip.Get_fast();}
|
||||
public Xoh_thm_hzip Thm__hzip() {return (Xoh_thm_hzip) pool__thm__hzip.Get_fast();}
|
||||
}
|
||||
@@ -16,21 +16,24 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.spaces; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_space_hzip implements Xoh_hzip_wkr {
|
||||
import gplx.core.brys.*; import gplx.core.threads.poolables.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_space_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__space;}
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int src_end, int rng_bgn, int rng_end) {// " " -> 27,9,4
|
||||
public Xoh_space_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int src_end, int rng_bgn, int rng_end) {
|
||||
int space_len = Bry_find_.Find_fwd_while(src, rng_end, src_end, Byte_ascii.Space) - rng_bgn;
|
||||
|
||||
stat_itm.Space_add(space_len);
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__space);
|
||||
Xoh_hzip_int_.Encode(1, bfr, space_len);
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
int space_len = rdr.Read_int_by_base85(1);
|
||||
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, space_len);
|
||||
return rdr.Pos();
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_space_hzip rv = new Xoh_space_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
||||
|
||||
@@ -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.spaces; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_space_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Len__8() {
|
||||
|
||||
@@ -20,13 +20,10 @@ import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_space_parser implements Html_doc_wkr {
|
||||
private final Xoh_hdoc_wkr wkr;
|
||||
private byte[] src; private int src_end;
|
||||
public Xoh_space_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
|
||||
public byte[] Hook() {return Hook_bry;}
|
||||
public void Init(byte[] src, int src_bgn, int src_end) {this.src = src; this.src_end = src_end;}
|
||||
public int Parse(int pos) {
|
||||
public int Parse(byte[] src, int src_bgn, int src_end, int pos) {
|
||||
int rng_end = Bry_find_.Find_fwd_while(src, pos + Hook_len, src_end, Byte_ascii.Space);
|
||||
|
||||
wkr.On_space(pos, rng_end);
|
||||
return rng_end;
|
||||
}
|
||||
|
||||
@@ -20,66 +20,54 @@ import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_doc_wkr__tag implements Html_doc_wkr {
|
||||
private Xoh_hdoc_wkr hdoc_wkr; private Xow_ttl_parser ttl_parser;
|
||||
private final Html_tag_rdr tag_rdr = new Html_tag_rdr(); private byte[] src; private int src_end;
|
||||
private final Xoh_lnki_parser wkr__lnki = new Xoh_lnki_parser();
|
||||
private final Xoh_lnke_parser wkr__lnke = new Xoh_lnke_parser();
|
||||
private final Xoh_hdr_parser wkr__hdr = new Xoh_hdr_parser();
|
||||
private final Xoh_thm_parse wkr__img_thm = new Xoh_thm_parse();
|
||||
private final Xoh_img_parser wkr__img_box = new Xoh_img_parser();
|
||||
public class Xoh_tag_parser implements Html_doc_wkr {
|
||||
private final Xoh_hdoc_wkr hdoc_wkr;
|
||||
private final Html_tag_rdr tag_rdr = new Html_tag_rdr();
|
||||
private final Xoh_hdr_parser wkr__hdr = new Xoh_hdr_parser();
|
||||
private final Xoh_lnki_parser wkr__lnki = new Xoh_lnki_parser(); private final Xoh_lnke_parser wkr__lnke = new Xoh_lnke_parser();
|
||||
private final Xoh_img_parser wkr__img = new Xoh_img_parser(); private final Xoh_thm_parser wkr__thm = new Xoh_thm_parser();
|
||||
private Xoh_hdoc_ctx hctx;
|
||||
public byte[] Hook() {return Byte_ascii.Angle_bgn_bry;}
|
||||
public Xoh_doc_wkr__tag Ctor(Xoh_hdoc_wkr hdoc_wkr, Xow_ttl_parser ttl_parser) {
|
||||
this.hdoc_wkr = hdoc_wkr; this.ttl_parser = ttl_parser;
|
||||
return this;
|
||||
public Xoh_tag_parser(Xoh_hdoc_wkr hdoc_wkr) {this.hdoc_wkr = hdoc_wkr;}
|
||||
public void Init(Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.hctx = hctx; tag_rdr.Init(src, src_bgn, src_end);
|
||||
}
|
||||
public void Init(byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src; this.src_end = src_end;
|
||||
tag_rdr.Init(src, src_bgn, src_end);
|
||||
}
|
||||
public int Parse(int pos) {
|
||||
public int Parse(byte[] src, int src_bgn, int src_end, int pos) {
|
||||
tag_rdr.Pos_(pos);
|
||||
int nxt_pos = tag_rdr.Pos() + 1; if (nxt_pos == src_end) return src_end;
|
||||
Html_tag cur = src[tag_rdr.Pos() + 1] == Byte_ascii.Slash ? tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__any) : tag_rdr.Tag__move_fwd_head();
|
||||
Html_tag nxt = null;
|
||||
if (cur.Tag_is_tail()) {
|
||||
if (cur.Tag_is_tail())
|
||||
hdoc_wkr.On_txt(pos, cur.Src_end());
|
||||
}
|
||||
else {
|
||||
Html_tag nxt = null;
|
||||
int cur_name_id = cur.Name_id();
|
||||
switch (cur_name_id) {
|
||||
case Html_tag_.Id__h2:
|
||||
case Html_tag_.Id__h3:
|
||||
case Html_tag_.Id__h4:
|
||||
case Html_tag_.Id__h5:
|
||||
case Html_tag_.Id__h6:
|
||||
case Html_tag_.Id__h2: case Html_tag_.Id__h3: case Html_tag_.Id__h4: case Html_tag_.Id__h5: case Html_tag_.Id__h6:
|
||||
int hdr_tag_bgn = cur.Src_bgn();
|
||||
nxt = tag_rdr.Tag__peek_fwd_head();
|
||||
if ( nxt.Name_id() == Html_tag_.Id__span
|
||||
&& nxt.Atrs__match_pair(Html_atr_.Bry__class , Atr__class__mw_headline)) {
|
||||
return wkr__hdr.Parse(hdoc_wkr, tag_rdr, src, cur_name_id, hdr_tag_bgn, nxt);
|
||||
&& nxt.Atrs__match_pair(Html_atr_.Bry__class , Xoh_hdr_parser.Bry__class__mw_headline)) {
|
||||
return wkr__hdr.Parse(hdoc_wkr, src, tag_rdr, cur_name_id, hdr_tag_bgn, nxt);
|
||||
}
|
||||
break;
|
||||
case Html_tag_.Id__a:
|
||||
nxt = tag_rdr.Tag__peek_fwd_head();
|
||||
if (nxt.Name_id() == Html_tag_.Id__img)
|
||||
return wkr__img_box.Parse(hdoc_wkr, src, tag_rdr, cur);
|
||||
else if (cur.Atrs__match_pair(Html_atr_.Bry__rel , Atr__rel__nofollow))
|
||||
if (nxt.Name_id() == Html_tag_.Id__img) {
|
||||
int rv = wkr__img.Parse(hdoc_wkr, hctx, src, tag_rdr, cur);
|
||||
hdoc_wkr.On_img(wkr__img);
|
||||
return rv;
|
||||
}
|
||||
else if (cur.Atrs__match_pair(Html_atr_.Bry__rel , Xoh_lnke_parser.Bry__rel__nofollow))
|
||||
return wkr__lnke.Parse(hdoc_wkr, tag_rdr, cur);
|
||||
else
|
||||
return wkr__lnki.Parse(hdoc_wkr, tag_rdr, src, cur, ttl_parser);
|
||||
return wkr__lnki.Parse(hdoc_wkr, hctx, src, tag_rdr, cur, hctx.Wiki__ttl_parser());
|
||||
case Html_tag_.Id__div:
|
||||
if (cur.Atrs__cls_has(Atr__class__thumb))
|
||||
return wkr__img_thm.Parse(hdoc_wkr, tag_rdr, src, cur);
|
||||
if (cur.Atrs__cls_has(Xoh_thm_parser.Atr__class__thumb))
|
||||
return wkr__thm.Parse(hdoc_wkr, hctx, src, tag_rdr, cur);
|
||||
break;
|
||||
}
|
||||
hdoc_wkr.On_txt(pos, cur.Src_end());
|
||||
}
|
||||
return cur.Src_end();
|
||||
}
|
||||
private static final byte[]
|
||||
Atr__class__mw_headline = Bry_.new_a7("mw-headline")
|
||||
, Atr__class__thumb = Bry_.new_a7("thumb")
|
||||
, Atr__rel__nofollow = Bry_.new_a7("nofollow")
|
||||
;
|
||||
}
|
||||
@@ -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.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
|
||||
public class Xoh_thm_bldr {
|
||||
private final Xoh_thm_wtr wtr = new Xoh_thm_wtr();
|
||||
private final byte[] div_2_magnify = Bry_.new_a7("bin/any/xowa/file/mediawiki.file/magnify-clip.png");
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int div_0_align, Xoh_img_bldr img_bldr, Bfr_arg div_2_href, Bfr_arg div_2_capt) {
|
||||
wtr.Clear();
|
||||
wtr.Div_0_align_(div_0_align);
|
||||
wtr.Div_1_id_(img_bldr.Fsdb_itm().Html_uid());
|
||||
wtr.Div_1_width_(img_bldr.Fsdb_itm().File_w());
|
||||
wtr.Div_1_img_(img_bldr.Wtr());
|
||||
wtr.Div_2_href_(div_2_href);
|
||||
wtr.Div_2_magnify_(hctx.Fsys__root(), div_2_magnify);
|
||||
wtr.Div_2_capt_(div_2_capt);
|
||||
wtr.Bfr_arg__add(bfr);
|
||||
}
|
||||
}
|
||||
@@ -16,80 +16,41 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.encoders.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xoh_thm_hzip implements Xoh_hzip_wkr {
|
||||
private Xow_ttl_parser ttl_parser; private int uid;
|
||||
public void Ttl_parser_(Xow_ttl_parser ttl_parser) {this.ttl_parser = ttl_parser; this.uid = 1;} // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
|
||||
public String Key() {return Xoh_hzip_dict_.Key__lnki;}
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int rng_bgn, int rng_end) {
|
||||
bfr.Add_mid(src, rng_bgn, rng_end);
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
byte lnki_type = rdr.Read_byte();
|
||||
int ns_id = rdr.Read_int_by_base85(1);
|
||||
int site_bgn = -1, site_end = -1;
|
||||
if (rdr.Is(Xoh_hzip_dict_.Escape)) {
|
||||
site_bgn = rdr.Pos();
|
||||
site_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
boolean site_exists = site_end - site_bgn > 0;
|
||||
int page_bgn = rdr.Pos();
|
||||
int page_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
int capt_bgn = -1, capt_end = -1;
|
||||
if (lnki_type != Xoh_lnki_dict_.Type__same) {
|
||||
capt_bgn = rdr.Pos();
|
||||
capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.divs.*;
|
||||
public class Xoh_thm_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
private final int[] flag_ary;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ ( 2);
|
||||
private final Xoh_img_hzip img_hzip = new Xoh_img_hzip();
|
||||
private final Xoh_thm_bldr bldr = new Xoh_thm_bldr();
|
||||
private final Bry_obj_ref div_2_capt = Bry_obj_ref.New_empty();
|
||||
public Xoh_thm_hzip() {this.flag_ary = flag_bldr.Val_ary();}
|
||||
public String Key() {return Xoh_hzip_dict_.Key__thm;}
|
||||
public Xoh_thm_hzip Encode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Hzip_stat_itm stat_itm, byte[] src, Xoh_thm_parser arg) {
|
||||
Xoh_thm_caption_parser div_2_capt_parser = arg.Capt_parser();
|
||||
flag_ary[ 0] = arg.Div_0_align();
|
||||
|
||||
byte[] page_bry = Bry_.Mid(src, page_bgn, page_end);
|
||||
Xoa_ttl ttl = ttl_parser.Ttl_parse(ns_id, page_bry); if (ttl == null) rdr.Fail("invalid ttl", "mid", String_.new_u8(page_bry)); // TODO: parse title based on site
|
||||
byte[] ttl__full_db = ttl.Full_db();
|
||||
|
||||
// gen html
|
||||
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
|
||||
if (site_exists) bfr.Add_str_a7("/site/").Add_mid(src, site_bgn, site_end);
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/"
|
||||
bfr.Add(ttl.Full_db());
|
||||
bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(++uid);
|
||||
bfr.Add_str_a7("\" title=\"");
|
||||
byte[] title_bry = site_exists ? ttl.Page_db() : ttl__full_db; // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A"
|
||||
bfr.Add(Html_utl.Escape_html_as_bry(title_bry)).Add_str_a7("\">");
|
||||
switch (lnki_type) {
|
||||
case Xoh_lnki_dict_.Type__same:
|
||||
if (ttl.Ns().Id_is_main())
|
||||
bfr.Add_mid(src, page_bgn, page_end);
|
||||
else
|
||||
bfr.Add(ttl.Full_txt());
|
||||
break;
|
||||
case Xoh_lnki_dict_.Type__diff:
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Type__trail:
|
||||
bfr.Add_mid(src, page_bgn, page_end);
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
break;
|
||||
}
|
||||
bfr.Add_str_a7("</a>");
|
||||
return rdr.Pos();
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__thm);
|
||||
Xoh_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
|
||||
bfr.Add_mid(src, div_2_capt_parser.Capt_bgn(), div_2_capt_parser.Capt_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
img_hzip.Encode(bfr, stat_itm, src, arg.Img_parser(), Bool_.N);
|
||||
return this;
|
||||
}
|
||||
// , Find_img_xatrs = Bry_.new_a7("xatrs='")
|
||||
// private static int[] Save_img_full_pow = new int[] {0, 1, 2};
|
||||
// private int Save_img_full(Bry_bfr bfr, Bry_rdr_old rdr, Hzip_stat_itm stat_itm, byte[] src, int src_len, int bgn, int pos) {
|
||||
// bfr.Add(Xoh_hzip_dict_.Bry__img_full);
|
||||
// int xatrs_bgn = Bry_find_.Move_fwd(src, Find_img_xatrs, pos, src_len); if (xatrs_bgn == Bry_find_.Not_found) return rdr.Warn("a.img_xatrs_missing", bgn, pos);
|
||||
// bry_rdr.Init(src, xatrs_bgn);
|
||||
// int a_cls = bry_rdr.Read_int_to_pipe();
|
||||
// int a_rel = bry_rdr.Read_int_to_pipe();
|
||||
// int img_rel = bry_rdr.Read_int_to_pipe();
|
||||
// byte meta = (byte)Bit_.Shift_lhs_to_int(Save_img_full_pow, a_cls, a_rel, img_rel);
|
||||
// bfr.Add_byte(meta); // meta
|
||||
// Xoh_hzip_int_.Encode(bfr, bry_rdr.Read_int_to_pipe()); // uid
|
||||
// bfr.Add(bry_rdr.Read_bry_to_pipe()).Add_byte_pipe(); // img_cls_other
|
||||
// bfr.Add(bry_rdr.Read_bry_to_apos()); // alt
|
||||
// bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
// return bry_rdr.Pos() + 2; // +2=/>
|
||||
// }
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
int flag = rdr.Read_int_by_base85(1);
|
||||
int capt_bgn = rdr.Pos();
|
||||
int capt_end = rdr.Find_fwd_lr();
|
||||
int rv = rdr.Pos();
|
||||
|
||||
flag_bldr.Decode(flag);
|
||||
int div_align = flag_ary[ 0];
|
||||
div_2_capt.Mid_(src, capt_bgn, capt_end);
|
||||
img_hzip.Decode(bfr, Bool_.N, hctx, hpg, rdr, src, rv);
|
||||
bldr.Make(bfr, hpg, hctx, src, div_align, img_hzip.Bldr(), img_hzip.Anch_href_arg(), div_2_capt);
|
||||
return rv;
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_thm_hzip rv = new Xoh_thm_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
}
|
||||
|
||||
@@ -16,71 +16,27 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_thm_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Page__basic() {
|
||||
try {
|
||||
Io_url html_dir = Io_url_.new_dir_("J:\\xowa\\dev\\html\\");
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
fxt.Hzip_mgr().Encode(bfr, fxt.Parser_fxt().Wiki(), Bry_.Empty, Io_mgr.Instance.LoadFilBry(html_dir.GenSubFil("temp_earth_mw.html")), new gplx.xowa.htmls.core.hzips.stats.Hzip_stat_itm());
|
||||
Io_mgr.Instance.SaveFilBry(html_dir.GenSubFil("temp_earth_mw_hzip.html"), bfr.To_bry_and_clear());
|
||||
} catch (Exception e) {
|
||||
Tfds.Write(e);
|
||||
}
|
||||
// fxt.Test__encode(""
|
||||
// , String_.Concat_lines_nl_skip_last
|
||||
// ( "<div class='thumb tleft'>"
|
||||
// , " <div id='xowa_file_div_1' class='thumbinner' style='width:220px;'>"
|
||||
// , " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'>"
|
||||
// , " <img id='xowa_file_img_1' alt='' "
|
||||
// , " src='file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/0/0/A.png/220px.png' "
|
||||
// , " width='220' height='119' class='thumbimage'>"
|
||||
// , " </a> "
|
||||
// , " <div class='thumbcaption'>"
|
||||
// , " <div class='magnify'>"
|
||||
// , " <a href='/wiki/File:A.png' class='@gplx.Internal protected' title='Enlarge'>"
|
||||
// , " <img src='file:///C:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png' width='15' height='11' alt=''>"
|
||||
// , " </a>"
|
||||
// , " </div>b"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , "</div>"
|
||||
// ));
|
||||
private String Html__basic = String_.Concat_lines_nl_skip_last
|
||||
( "<div class='thumb tleft'>"
|
||||
, " <div id='xothm_0' class='thumbinner' style='width:0px;'>"
|
||||
, "<a href='/wiki/File:A.png' class='image'><img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='119' class='thumbimage'></a>"
|
||||
, " <div class='thumbcaption'>"
|
||||
, " <div class='magnify'>"
|
||||
, " <a href='/wiki/File:A.png' class='@gplx.Internal protected' title='Enlarge'>"
|
||||
, " <img src='file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png' width='15' height='11' alt=''>"
|
||||
, " </a>"
|
||||
, " </div>abc"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
);
|
||||
@Test public void Page__basic() {
|
||||
fxt.Test__decode("~&#abc~!T8#T\"DA.png~", Html__basic);
|
||||
}
|
||||
@Test public void Dump() {
|
||||
// fxt.Exec_write_to_fsys(Io_url_.new_dir_("J:\\xowa\\dev\\html\\"), "temp_earth_xo.html");
|
||||
}
|
||||
}
|
||||
/*
|
||||
<div class="thumb tleft">
|
||||
<div id="xowa_file_div_60" class="thumbinner" style="width:220px;">
|
||||
<a href="/wiki/File:Protoplanetary-disk.jpg" class="image" xowa_title="Protoplanetary-disk.jpg">
|
||||
<img id="xowa_file_img_60" alt=""
|
||||
src="file:///J:/xowa/file/commons.wikimedia.org/thumb/7/1/7/c/Protoplanetary-disk.jpg/220px.jpg"
|
||||
width="220" height="119" class="thumbimage">
|
||||
</a>
|
||||
<div class="thumbcaption">
|
||||
<div class="magnify">
|
||||
<a href="/wiki/File:Protoplanetary-disk.jpg" class="@gplx.Internal protected" title="Enlarge">
|
||||
<img src="file:///J:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png" width="15" height="11" alt="">
|
||||
</a>
|
||||
</div>Artist's impression of the early Solar System's planetary disk
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="thumb tleft">
|
||||
<div id="xowa_file_div_60" class="thumbinner" style="width:0px;">
|
||||
<a href="/wiki/File:Protoplanetary-disk.jpg" class="image" xowa_title="Protoplanetary-disk.jpg" data-xoimg='1|2|3|4|5|6|A.png'>
|
||||
<img id="xowa_file_img_60" alt=""
|
||||
src=""
|
||||
width="0" height="0" class="thumbimage">
|
||||
</a>
|
||||
<div class="thumbcaption">
|
||||
<div class="magnify">
|
||||
<a href="/wiki/File:Protoplanetary-disk.jpg" class="@gplx.Internal protected" title="Enlarge">
|
||||
<img src="file:///J:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png" width="15" height="11" alt="">
|
||||
</a>
|
||||
</div>Artist's impression of the early Solar System's planetary disk
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
*/
|
||||
|
||||
@@ -1,74 +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.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.langs.htmls.parsers.styles.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
public class Xoh_thm_parse {
|
||||
/*
|
||||
<div class="thumb tleft">
|
||||
<div id="xowa_file_div_60" class="thumbinner" style="width:220px;">
|
||||
<a href="/wiki/File:Protoplanetary-disk.jpg" class="image" xowa_title="Protoplanetary-disk.jpg">
|
||||
<img id="xowa_file_img_60" alt=""
|
||||
src="file:///J:/xowa/file/commons.wikimedia.org/thumb/7/1/7/c/Protoplanetary-disk.jpg/220px.jpg"
|
||||
width="220" height="119" class="thumbimage">
|
||||
</a>
|
||||
<div class="thumbcaption">
|
||||
<div class="magnify">
|
||||
<a href="/wiki/File:Protoplanetary-disk.jpg" class="@gplx.Internal protected" title="Enlarge">
|
||||
<img src="file:///J:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png" width="15" height="11" alt="">
|
||||
</a>
|
||||
</div>Artist's impression of the early Solar System's planetary disk
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
*/
|
||||
private final Xoh_anch_href_parser href_parser = new Xoh_anch_href_parser();
|
||||
private final Xoh_img_parser img_parser = new Xoh_img_parser();
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag div_0) {
|
||||
int rng_bgn = div_0.Src_bgn(), rng_end = div_0.Src_end();
|
||||
byte thm_align = div_0.Atrs__cls_find_1st(Xop_lnki_align_h.Hash);
|
||||
Html_tag div_1 = tag_rdr.Tag__move_fwd_head(Bry__cls__thumbinner);
|
||||
int div_width = div_1.Atrs__style_get_as_int(Html_atr_style_.Bry__width);
|
||||
Html_tag anch = tag_rdr.Tag__move_fwd_head(Xoh_img_parser.Bry__cls__anch__image);
|
||||
Html_atr href = anch.Atrs__get_by(Html_atr_.Bry__href);
|
||||
rdr.Ctor_by_page(Bry_.Empty, src, src.length);
|
||||
href_parser.Parse(rdr, hdoc_wkr.Ctx().Wiki(), href.Val_bgn(), href.Val_end());
|
||||
img_parser.Parse(hdoc_wkr, src, tag_rdr, anch);
|
||||
tag_rdr.Tag__move_fwd_head(Bry__cls__thumbcaption);
|
||||
tag_rdr.Tag__move_fwd_head(Bry__cls__magnify);
|
||||
Html_tag div_3_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
|
||||
int capt_bgn = div_3_tail.Src_end();
|
||||
Html_tag div_4_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
|
||||
int capt_end = div_4_tail.Src_bgn();
|
||||
tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
|
||||
Html_tag div_0_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
|
||||
rng_end = div_0_tail.Src_end();
|
||||
Tfds.Write(thm_align, div_width, Bry_.Mid(src, href_parser.Page_bgn(), href_parser.Page_end()), img_parser.Img_w(), img_parser.Img_h(), Bry_.Mid_w_trim(src, capt_bgn, capt_end), rng_end);
|
||||
hdoc_wkr.On_img_thm(rng_bgn, rng_end);
|
||||
return rng_end;
|
||||
}
|
||||
private static final byte[]
|
||||
Bry__cls__thumbinner = Bry_.new_a7("thumbinner")
|
||||
, Bry__cls__thumbcaption = Bry_.new_a7("thumbcaption")
|
||||
, Bry__cls__magnify = Bry_.new_a7("magnify")
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.langs.htmls.parsers.styles.*;
|
||||
import gplx.xowa.htmls.core.wkrs.thms.divs.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
public class Xoh_thm_parser implements Html_atr_style_wkr {
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public byte Div_0_align() {return div_0_align;} private byte div_0_align;
|
||||
public int Div_1_width() {return div_1_width;} private int div_1_width;
|
||||
public Xoh_img_parser Img_parser() {return img_parser;} private final Xoh_img_parser img_parser = new Xoh_img_parser();
|
||||
public Xoh_thm_caption_parser Capt_parser() {return capt_parser;} private final Xoh_thm_caption_parser capt_parser = new Xoh_thm_caption_parser();
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag div_0) {
|
||||
tag_rdr.Rdr().Init_by_hook("thm", div_0.Src_bgn(), div_0.Src_bgn());
|
||||
this.rng_bgn = div_0.Src_bgn();
|
||||
this.div_0_align = div_0.Atrs__cls_find_or_fail(gplx.xowa.parsers.lnkis.Xop_lnki_align_h_.Hash);
|
||||
Html_tag div_1 = tag_rdr.Tag__move_fwd_head(); // <div class='thumbinner'>
|
||||
this.div_1_width = -1;
|
||||
Html_atr_style_parser_.Parse(div_1, this); // " style='120px'"
|
||||
img_parser.Parse(hdoc_wkr, hctx, src, tag_rdr, tag_rdr.Tag__move_fwd_head()); // <a>
|
||||
capt_parser.Parse(hdoc_wkr, tag_rdr, src, tag_rdr.Tag__move_fwd_head()); // <div>
|
||||
tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); // </div> for div_1
|
||||
Html_tag div_0_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); // </div> for div_0
|
||||
this.rng_end = div_0_tail.Src_end();
|
||||
hdoc_wkr.On_thm(this);
|
||||
return rng_end;
|
||||
}
|
||||
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, Html_atr_style_.Bry__width))
|
||||
this.div_1_width = Bry_.To_int_or__lax(src, val_bgn, val_end, -1);
|
||||
return true;
|
||||
}
|
||||
public static final byte[]
|
||||
Atr__class__thumb = Bry_.new_a7("thumb")
|
||||
, Atr__class__thumbinner = Bry_.new_a7("thumbinner")
|
||||
;
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_wtr.java
Normal file
61
400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_wtr.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.brys.fmtrs.*; import gplx.core.brys.args.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
|
||||
public class Xoh_thm_wtr extends gplx.core.brys.Bfr_arg_base {
|
||||
private final Bry_obj_ref div_0_align = Bry_obj_ref.New_empty();
|
||||
private final Bfr_arg__id div_1_id_val = new Bfr_arg__id();
|
||||
private final Bfr_arg__int div_1_width = new Bfr_arg__int(-1);
|
||||
private final Bfr_arg__html_atr
|
||||
div_1_id = new Bfr_arg__html_atr(Html_atr_.Bry__id)
|
||||
, div_2_href = new Bfr_arg__html_atr(Html_atr_.Bry__href)
|
||||
;
|
||||
private final Bfr_arg__bry_ary div_2_magnify = new Bfr_arg__bry_ary();
|
||||
private Bfr_arg div_1_img = Bfr_arg_.Noop, div_2_capt = Bfr_arg_.Noop;
|
||||
public Xoh_thm_wtr Div_0_align_(int v) {div_0_align.Val_(gplx.xowa.parsers.lnkis.Xop_lnki_align_h_.To_bry(v)); return this;}
|
||||
public Xoh_thm_wtr Div_1_id_(int v) {div_1_id.Set_by_arg(div_1_id_val.Set(Prefix__div_id, v)); return this;}
|
||||
public Xoh_thm_wtr Div_1_width_(int v) {div_1_width.Set(v); return this;}
|
||||
public Xoh_thm_wtr Div_1_img_(Xoh_img_wtr v) {div_1_img = v; return this;}
|
||||
public Xoh_thm_wtr Div_2_href_(Bfr_arg v) {div_2_href.Set_by_arg(v); return this;}
|
||||
public Xoh_thm_wtr Div_2_magnify_(byte[]... v) {div_2_magnify.Set(v); return this;}
|
||||
public Xoh_thm_wtr Div_2_capt_(Bfr_arg v) {div_2_capt = v; return this;}
|
||||
public Xoh_thm_wtr Clear() {
|
||||
Bfr_arg_.Clear(div_0_align, div_1_id, div_1_width, div_1_img, div_2_href, div_2_magnify, div_2_capt);
|
||||
return this;
|
||||
}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, div_0_align, div_1_id, div_1_width, div_1_img, div_2_href, div_2_magnify, div_2_capt);
|
||||
}
|
||||
public static final byte[] Prefix__div_id = Bry_.new_a7("xothm_");
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb t~{div_0_align}\">"
|
||||
, " <div~{div_1_id} class=\"thumbinner\" style=\"width:~{div_1_width}px;\">"
|
||||
, "~{div_1_img}"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a~{div_2_href} class=\"@gplx.Internal protected\" title=\"Enlarge\">"
|
||||
, " <img src=\"~{div_2_magnify}\" width=\"15\" height=\"11\" alt=\"\">"
|
||||
, " </a>"
|
||||
, " </div>~{div_2_capt}"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
), "div_0_align", "div_1_id", "div_1_width", "div_1_img", "div_2_href", "div_2_magnify", "div_2_capt");
|
||||
}
|
||||
@@ -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.thms.divs; 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.thms.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_thm_caption_parser {
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
|
||||
public int Capt_end() {return capt_end;} private int capt_end;
|
||||
public Xoh_thm_magnify_parser Magnify_parser() {return magnify_parser;} private final Xoh_thm_magnify_parser magnify_parser = new Xoh_thm_magnify_parser();
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag div_caption) {
|
||||
this.rng_bgn = div_caption.Src_bgn();
|
||||
magnify_parser.Parse(hdoc_wkr, tag_rdr, src, div_caption);
|
||||
this.capt_bgn = magnify_parser.Magnify_tail_div().Src_end();
|
||||
Html_tag div_caption_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
|
||||
this.capt_end = div_caption_tail.Src_bgn();
|
||||
capt_end = Bry_find_.Find_bwd_non_ws_or_end(src, capt_end - 1, -1) + 1;
|
||||
this.rng_end = div_caption_tail.Src_end();
|
||||
return rng_end;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.thms.divs; 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.thms.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_thm_magnify_parser {
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public boolean Exists() {return exists;} private boolean exists;
|
||||
public Html_tag Magnify_tail_div() {return magnify_tail_div;} private Html_tag magnify_tail_div;
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag div_caption) {
|
||||
// rdr.Init_by_sub(tag_rdr.Rdr(), "thm.magnify", div_caption.Src_bgn(), div_caption.Src_end());
|
||||
this.rng_bgn = div_caption.Src_bgn(); this.rng_end = div_caption.Src_end();
|
||||
Html_tag div_magnify = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__div); // <div class="magnify">
|
||||
this.exists = div_magnify.Src_exists();
|
||||
if (exists) {
|
||||
magnify_tail_div = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
|
||||
this.rng_end = magnify_tail_div.Src_end();
|
||||
tag_rdr.Pos_(rng_end);
|
||||
}
|
||||
return rng_end;
|
||||
}
|
||||
}
|
||||
@@ -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/>.
|
||||
*/
|
||||
//namespace gplx.xowa.htmls.core.to_delete {
|
||||
// using gplx.core.primitives; using gplx.core.brys; using gplx.core.btries; using gplx.dbs; using gplx.core.ios;
|
||||
// using gplx.core.primitives; using gplx.core.btries; using gplx.dbs; using gplx.core.ios;
|
||||
// using gplx.xowa.wikis.dbs; using gplx.xowa.wikis.pages; using gplx.xowa.htmls.core.makes.imgs; using gplx.xowa.wikis.pages.skins;
|
||||
// using gplx.xowa.wikis.data; using gplx.xowa.wikis.data.tbls; using gplx.xowa.guis;
|
||||
// public class Xohd_page_html_mgr__load {
|
||||
@@ -20,8 +20,5 @@ import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_txt_parser implements Html_txt_wkr {
|
||||
private final Xoh_hdoc_wkr wkr;
|
||||
public Xoh_txt_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
|
||||
public void Init(byte[] src, int src_bgn, int src_end) {}
|
||||
public void Parse(int rng_bgn, int rng_end) {
|
||||
wkr.On_txt(rng_bgn, rng_end);
|
||||
}
|
||||
public void Parse(int rng_bgn, int rng_end) {wkr.On_txt(rng_bgn, rng_end);}
|
||||
}
|
||||
|
||||
@@ -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.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_head_mgr implements Bry_fmtr_arg {
|
||||
public class Xoh_head_mgr extends gplx.core.brys.Bfr_arg_base {
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page;
|
||||
private Xoh_head_itm__base[] itms; private int itms_len;
|
||||
private Xoh_head_wtr wtr = new Xoh_head_wtr();
|
||||
@@ -72,7 +72,7 @@ public class Xoh_head_mgr implements Bry_fmtr_arg {
|
||||
for (int i = 0; i < itms_len; ++i)
|
||||
itms[i].Clear();
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {Write(bfr, app, wiki, page);}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {Write(bfr, app, wiki, page);}
|
||||
public void Write(Bry_bfr bfr, Xoae_app app, Xowe_wiki wiki, Xoae_page page) {
|
||||
Set_wkrs();
|
||||
wtr.Init(bfr);
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.numbers.*;
|
||||
public class Xow_fragment_mgr implements GfoInvkAble {
|
||||
public Xow_fragment_mgr(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
|
||||
@@ -35,10 +35,11 @@ public class Xoh_href_parser {
|
||||
switch (((Byte_obj_val)seg_obj).Val()) {
|
||||
case Seg_xcmd_tid: // convert "/xcmd/a" to "xowa-cmd:a"
|
||||
raw = Bry_.Add(Gfo_protocol_itm.Bry_xcmd, Bry_.Mid(raw, btrie.Match_pos()));
|
||||
bgn = 0;
|
||||
break;
|
||||
case Seg_wiki_tid: // skip "/wiki/" or "/site/"
|
||||
case Seg_site_tid:
|
||||
case Seg_wiki_tid: // add domain_bry; NOTE: needed for url-like pages; EX:"/wiki/http://A"; PAGE:esolangs.org/wiki/Language_list; DATE:2015-11-14
|
||||
raw = Bry_.Add(wiki.Domain_bry(), raw);
|
||||
break;
|
||||
case Seg_site_tid: // skip "/site"
|
||||
bgn = btrie.Match_pos();
|
||||
break;
|
||||
default:
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user